With the exception of SVG (more on that later), today’s Web platform offers only one built-in mechanism to isolate one chunk of code from another — and it ain’t pretty. Yup, I am talking about iframes. For most encapsulation needs, frames are too heavy and restrictive.Yeah... this guy has no idea what he's talking about. Javascript is an incredibly flexible language and you can do most OO things with it, although it's true that it doesn't have private members... there's a huge difference between actual secure isolation between components (which is what iFrames give you) and encapsulation.
function MyObject() {
var private = 0;
this.public = 1;
}
var temp = new MyObject();
alert(temp.private); // undefined
alert(temp.public); // 1
stephen@jellyfish:~$ js
js> function foo() {
var privateThing = 0;
this.getPrivateThing = function() { return privateThing; }
this.setprivateThing = function(val) { privateThing = val; }
this.visibleThing = 2;
}
js> var bar = new foo();
js> bar.getPrivateThing();
0
js> bar.setPrivateThing(3);
js> print(bar.getPrivateThing());
3
js> print(bar.privateThing);
undefined
js> print(bar.visibleThing);
2
js> bar.visibleThing = 99
99
js> print(bar.visibleThing);
99
js> var gum = new foo();
js> print(bar.getPrivateThing());
3
js> print(gum.getPrivateThing());
0
js> print(bar.visibleThing);
99
js> print(gum.visibleThing);
2
js> ^C
stephen@jellyfish:~$
td { background-color: gray; } style that wasn't intended to apply to the packageable widgets I use. The "shadow DOM" is basically way for a DOM element to say "do not cascade styles down this branch of the tree".td { background-color: gray; } is just asking for trouble - even without JQuery UI. If you're putting a lot of specific styling in selectors for things like TD, DIV and SPAN I'd be surprised if you're not having to put in classes for all kinds of special cases that have a bunch of !important stuff in them, even before any UI libraries.final and private declarations than they are about actually writing classes/objects that are so well-considered that nobody cares to subclass or poke around inside). !important all over everything, or start adding additional selectors for the sole purpose of manipulating specificity weights. div.someclass#myspecialdombranch {
default-ruleset: browser;
}!importants or specificity formulation). But yeah, I can see how this might be really helpful, particularly in a group context.« Older Visceral Games launches a very innovative ad campa... | The Daily Diff is a timed spot... Newer »
This thread has been archived and is closed to new comments
posted by Artw at 4:08 PM on January 18, 2011