kangax wrote: > ... > Ken, > > I wanted to keep $W consistent with the rest of the library - be a > simple shortcut for creating a new instance of NodeWrapper. Just like ` > $H` returns `new Hash` and $R returns `new ObjectRange`, $W should > probably return `new NodeWrapper`. $W is also responsible for > "transforming" string parameter into an actual element (via > `document.getElementById`): > > ... > this.$W = function(element) { > if (typeof element == 'string') { > element = document.getElementById(element); > } > return new Prototype.Node(element); > }; > ... > > Using such "proxy" helper ($W) also ensures NodeWrapper is always > called as a constructor. There are less chances that a user will > mistakenly call `NodeWrapper` as a function and pollute the global > scope. It, therefore, allows us to get rid of "this instanceof > Prototype.Node" check: > > new Prototype.Node('foo'); // returns a wrapper > Prototype.Node('foo'); // boom! returns undefined and creates a global > `source`/`raw` property > That makes sense. I was just thinking where it might be confusing that:
$W('foo') instanceof Prototype.Node; // true but seeing it written out like that does make sense. > Good point about passing a wrapper into a wrapper : ) Would it make > sense to return a wrapper itself or a "clone" of it? Would there ever > be a need for a cloned wrapper? > The only case I can think of is when there is an item in memory with the same id as one on the page. I don't know how we would handle that case. Maybe the caching system could handle that somehow. > As far as caching, I'm afraid that storing reference to a wrapper on a > node itself could lead to circular references (which as we know "leak" > in IE's JScript). Having a separate cache-table and map elements to > wrappers by an element's id (or a custom property of an element) seems > more appropriate. > What about this caching idea: http://gist.github.com/6609 > I also think that #update, #insert, #replace, etc. should allow to > accept a wrapper (besides an element or a string): > > $W('foo').insert($W('bar')); > > This should be as easy as giving wrapper `toElement`/`toHTML` methods > (since `update`/`insert` delegate to those when available) > Definitely. > -- > kangax Ken Snyder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---