kangax wrote: > On Aug 22, 11:30 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote: > >>> I'm not sure if we should "pre-wrap" elements or do the "lazy init". >>> First approach "hits" the memory consumption, while second - run-time >>> performance. We'll need benchmarks for this. >>> >> Yeah. I know you were initially thinking pre-wrap, and my first >> instinct was lazy-init (of course!), which was part of the point of my >> question. If I have $$() for my lazy-init needs, I'm less likely to >> weigh in and say $$W() should be lazy-init as well. >> >> That said, lazy-init seems pretty cheap; essentially an extra >> comparison on each item() call. Thinking out loud: >> >> initialize: function(source) { >> this.source = source; >> this.wrappers = []; >> > > Not sure if having two arrays in each `NodeList` compensates for the > load-time save : ) Definitely an interesting idea, though. I'll think > about it. > ... > -- > kangax > I think you may have already mentioned this, but what about lazy wrapping but altering the raw array? (see below)
Of course an argument /against/ lazy wrapping is that we would have to make "this.raw" a private property because you wouldn't know if it contains wrapped or unwrapped elements. - Ken initialize: function(array) { this.raw = array; this.length = this.raw.length; }... item: function(index) { if (index < 0 || index >= this.length) return null; // $W either instantiates a new wrapper, or returns the value // if the value is already an instance of Prototype.ElementWrapper this.raw[index] = $W(this.raw[index]); return this.raw[index]; }... _each: function(iterator) { var index = 0; while (index < this.length) iterator(this.item(index), index++); } --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---