Re: dojo.forEach scope

View: New views
4 Messages — Rating Filter:   Alert me  

Re: dojo.forEach scope

by Eugene Lazutkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Array functions are patterned after the array methods in the upcoming
ECMA-262 5th edition. The idea was to provide shims for methods of the
same name, or delegate to them if they are available. We tried to match
the behavior down to the argument list, and how the callback is called.

(Sidenote: we need to provide the fallback to native methods. Right now
we don't do that because of the performance problems with Firefox'
implementation.)

We used the Mozilla spec at that moment because that was the only
codified thing available. Now, when the release candidate is published,
we can revise our implementation to match it more closely. Namely the
standard changed the default scope from the global to the undefined (it
is true for other array methods). We need to update our implementation too.

There is a reason why forEach doesn't support early termination:
performance. If it checks for an exit value, it will penalize code that
doesn't need to terminate early. But I understand the need for a
versatile iterating function, and I think it would be a good candidate
for dojox.lang.functional methods. we can call it each() just like other
libraries do.

Thanks,

Eugene Lazutkin
Dojo Toolkit, Committer
http://lazutkin.com/

On 09/04/2009 09:12 AM, Les Szklanny wrote:

> IMHO you rely too much on the Mozilla spec, which is not that great.
>
> Take for example the ability to early terminate the forEach loop.  This
> feature is not in the Mozilla spec, but all other libraries (Ext,
> JQuery, Prototype, MooTools) provide the ability to early terminate forEach.
>
> In Dojo, however, I have to use dojo.some or dojo.every to simulate
> breaking out of forEach, which is not intuitive.
>
> Les
>
> On Fri, Sep 4, 2009 at 8:44 AM, Peter E Higgins <dante@...
> <mailto:dante@...>> wrote:
>
>     From:
>     https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:forEach
>
>     ""
>     If a thisObject parameter is provided to forEach, it will be used as the
>     this for each invocation of the callback. If it is not provided, or is
>     null, the global object associated with callback is used instead.
>     ""
>
>     You can access the original array as "arr" in your example, just as you
>     would propose be 'this'.  In jQuery, 'this' is the item, which imo is
>     completely wrong. Easier to stick to generally accepted specs.
>
>     Maybe I'm just missing the advantage to referring to your original array
>     as 'this' over the third arg?
>
>     You code could also be written as:
>     var array = [1,2,3];
>     dojo.forEach(array, function(el, i){ }, array); // if you must.
>
>     Regards,
>     Peter
>     > Why dojo.forEach default scope is dojo.global and not e.g. the array
>     > or the element being processed?
>     >
>     > var array = [1,2,3];
>     > var scope = array;
>     > dojo.forEach(array, function(element, index, arr) {
>     >    debugger;
>     > }, scope);
>     >
>     > If I don't provide scope, 'this' object defaults to dojo.global, which
>     > is not as useful.
>     >
>
>     --
>     Peter E Higgins
>     Dojo Project Lead : http://dojotoolkit.org
>
>     _______________________________________________
>     FAQ: http://dojotoolkit.org/support/faq
>     Book: http://docs.dojocampus.org
>     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: dojo.forEach scope

by Eugene Lazutkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

12ms?
http://lazutkin.com/blog/2008/mar/23/javascript-edp-and-0ms-timeouts/
--- to save on reading scroll down to the table.

And allow me to disagree politely with your performance vs. convenience
assessment.

Thanks,

Eugene Lazutkin
Dojo Toolkit, Committer
http://lazutkin.com/

On 09/04/2009 08:04 PM, Les Szklanny wrote:

>>>> There is a reason why forEach doesn't support early termination:
> performance. If it checks for an exit value, it will penalize code that
> doesn't need to terminate early.
>
> Performance degradation is negligible -  forEach is used for
> convenience, not for performance anyway.
>
> Run the code below at http://docs.dojocampus.org/dojo/NodeList
>
> var els = dojo.query('*');
> console.log(els.length)
> console.time('dojo');
> dojo.forEach(els, function(e){return true;});
> console.timeEnd('dojo');
> console.time('jQuery');
> jQuery.each(els, function(e){return true;});
> console.timeEnd('jQuery');
>
> http://docs.dojocampus.org/dojo/NodeList
>
> I see these results on my computer:
>
> elements: 1616
> dojo: 12ms
> jQuery: 12ms
>
> You will need to jQuerify the page:
>
> http://www.learningjquery.com/2006/12/jquerify-bookmarklet
>
>
>
> On Fri, Sep 4, 2009 at 6:43 PM, Eugene Lazutkin
> <eugene.lazutkin@... <mailto:eugene.lazutkin@...>> wrote:
>
>     Array functions are patterned after the array methods in the upcoming
>     ECMA-262 5th edition. The idea was to provide shims for methods of the
>     same name, or delegate to them if they are available. We tried to match
>     the behavior down to the argument list, and how the callback is called.
>
>     (Sidenote: we need to provide the fallback to native methods. Right now
>     we don't do that because of the performance problems with Firefox'
>     implementation.)
>
>     We used the Mozilla spec at that moment because that was the only
>     codified thing available. Now, when the release candidate is published,
>     we can revise our implementation to match it more closely. Namely the
>     standard changed the default scope from the global to the undefined (it
>     is true for other array methods). We need to update our
>     implementation too.
>
>     There is a reason why forEach doesn't support early termination:
>     performance. If it checks for an exit value, it will penalize code that
>     doesn't need to terminate early. But I understand the need for a
>     versatile iterating function, and I think it would be a good candidate
>     for dojox.lang.functional methods. we can call it each() just like other
>     libraries do.
>
>     Thanks,
>
>     Eugene Lazutkin
>     Dojo Toolkit, Committer
>     http://lazutkin.com/
>
>     On 09/04/2009 09:12 AM, Les Szklanny wrote:
>     > IMHO you rely too much on the Mozilla spec, which is not that great.
>     >
>     > Take for example the ability to early terminate the forEach loop.
>      This
>     > feature is not in the Mozilla spec, but all other libraries (Ext,
>     > JQuery, Prototype, MooTools) provide the ability to early
>     terminate forEach.
>     >
>     > In Dojo, however, I have to use dojo.some or dojo.every to simulate
>     > breaking out of forEach, which is not intuitive.
>     >
>     > Les
>     >
>     > On Fri, Sep 4, 2009 at 8:44 AM, Peter E Higgins
>     <dante@... <mailto:dante@...>
>     > <mailto:dante@... <mailto:dante@...>>> wrote:
>     >
>     >     From:
>     >    
>     https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:forEach
>     >
>     >     ""
>     >     If a thisObject parameter is provided to forEach, it will be
>     used as the
>     >     this for each invocation of the callback. If it is not
>     provided, or is
>     >     null, the global object associated with callback is used instead.
>     >     ""
>     >
>     >     You can access the original array as "arr" in your example,
>     just as you
>     >     would propose be 'this'.  In jQuery, 'this' is the item, which
>     imo is
>     >     completely wrong. Easier to stick to generally accepted specs.
>     >
>     >     Maybe I'm just missing the advantage to referring to your
>     original array
>     >     as 'this' over the third arg?
>     >
>     >     You code could also be written as:
>     >     var array = [1,2,3];
>     >     dojo.forEach(array, function(el, i){ }, array); // if you must.
>     >
>     >     Regards,
>     >     Peter
>     >     > Why dojo.forEach default scope is dojo.global and not e.g.
>     the array
>     >     > or the element being processed?
>     >     >
>     >     > var array = [1,2,3];
>     >     > var scope = array;
>     >     > dojo.forEach(array, function(element, index, arr) {
>     >     >    debugger;
>     >     > }, scope);
>     >     >
>     >     > If I don't provide scope, 'this' object defaults to
>     dojo.global, which
>     >     > is not as useful.
>     >     >
>     >
>     >     --
>     >     Peter E Higgins
>     >     Dojo Project Lead : http://dojotoolkit.org
>     >
>     >     _______________________________________________
>     >     FAQ: http://dojotoolkit.org/support/faq
>     >     Book: http://docs.dojocampus.org
>     >     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >
>     >
>     >
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > FAQ: http://dojotoolkit.org/support/faq
>     > Book: http://docs.dojocampus.org
>     > Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>     _______________________________________________
>     FAQ: http://dojotoolkit.org/support/faq
>     Book: http://docs.dojocampus.org
>     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: dojo.forEach scope

by Eugene Lazutkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I didn't expect that you want me to test the obvious, but sure, I can
spare 2 minutes:

var a = [];
for(var i = 0; i < 1000000; ++i) a.push(i);
var dojoTime = new Date().getTime();
dojo.forEach(a, function(){ return true; });
dojoTime = new Date().getTime() - dojoTime;
var jqTime = new Date().getTime();
jQuery.each(a, function(){ return true; });
jqTime = new Date().getTime() - jqTime;
console.log("jQuery is ",
  (jqTime / dojoTime).toFixed(2),
  " slower than Dojo on iterating through arrays");

On my computer (FF/Linux 3.5) it prints:

jQuery is  2.93  slower than Dojo on iterating through arrays

I ran it 10 times and the number changes from time to time but the
result is > 2.7 on all attempts.

Google Chrome for Linux:

jQuery is 3.09 slower than Dojo on iterating through arrays

Opera 10.0 for Linux:

jQuery is 1.49 slower than Dojo on iterating through arrays

I think if we reverted to the native implementation, numbers would be
even more impressive. And dojox.lang.functional.array methods being more
lax are generally faster than the implementation in the Dojo base.

Thanks,

Eugene Lazutkin
Dojo Toolkit, Committer
http://lazutkin.com/

On 09/04/2009 09:10 PM, Les Szklanny wrote:

> Can you come up with an example that would back up your statement that
> there's any noticeable performance gain by not checking the return value
> of the function?
>
> On Fri, Sep 4, 2009 at 8:48 PM, Eugene Lazutkin
> <eugene.lazutkin@... <mailto:eugene.lazutkin@...>> wrote:
>
>     12ms?
>     http://lazutkin.com/blog/2008/mar/23/javascript-edp-and-0ms-timeouts/
>     --- to save on reading scroll down to the table.
>
>     And allow me to disagree politely with your performance vs. convenience
>     assessment.
>
>     Thanks,
>
>     Eugene Lazutkin
>     Dojo Toolkit, Committer
>     http://lazutkin.com/
>
>     On 09/04/2009 08:04 PM, Les Szklanny wrote:
>     >>>> There is a reason why forEach doesn't support early termination:
>     > performance. If it checks for an exit value, it will penalize code
>     that
>     > doesn't need to terminate early.
>     >
>     > Performance degradation is negligible -  forEach is used for
>     > convenience, not for performance anyway.
>     >
>     > Run the code below at http://docs.dojocampus.org/dojo/NodeList
>     >
>     > var els = dojo.query('*');
>     > console.log(els.length)
>     > console.time('dojo');
>     > dojo.forEach(els, function(e){return true;});
>     > console.timeEnd('dojo');
>     > console.time('jQuery');
>     > jQuery.each(els, function(e){return true;});
>     > console.timeEnd('jQuery');
>     >
>     > http://docs.dojocampus.org/dojo/NodeList
>     >
>     > I see these results on my computer:
>     >
>     > elements: 1616
>     > dojo: 12ms
>     > jQuery: 12ms
>     >
>     > You will need to jQuerify the page:
>     >
>     > http://www.learningjquery.com/2006/12/jquerify-bookmarklet
>     >
>     >
>     >
>     > On Fri, Sep 4, 2009 at 6:43 PM, Eugene Lazutkin
>     > <eugene.lazutkin@... <mailto:eugene.lazutkin@...>
>     <mailto:eugene.lazutkin@...
>     <mailto:eugene.lazutkin@...>>> wrote:
>     >
>     >     Array functions are patterned after the array methods in the
>     upcoming
>     >     ECMA-262 5th edition. The idea was to provide shims for
>     methods of the
>     >     same name, or delegate to them if they are available. We tried
>     to match
>     >     the behavior down to the argument list, and how the callback
>     is called.
>     >
>     >     (Sidenote: we need to provide the fallback to native methods.
>     Right now
>     >     we don't do that because of the performance problems with Firefox'
>     >     implementation.)
>     >
>     >     We used the Mozilla spec at that moment because that was the only
>     >     codified thing available. Now, when the release candidate is
>     published,
>     >     we can revise our implementation to match it more closely.
>     Namely the
>     >     standard changed the default scope from the global to the
>     undefined (it
>     >     is true for other array methods). We need to update our
>     >     implementation too.
>     >
>     >     There is a reason why forEach doesn't support early termination:
>     >     performance. If it checks for an exit value, it will penalize
>     code that
>     >     doesn't need to terminate early. But I understand the need for a
>     >     versatile iterating function, and I think it would be a good
>     candidate
>     >     for dojox.lang.functional methods. we can call it each() just
>     like other
>     >     libraries do.
>     >
>     >     Thanks,
>     >
>     >     Eugene Lazutkin
>     >     Dojo Toolkit, Committer
>     >     http://lazutkin.com/
>     >
>     >     On 09/04/2009 09:12 AM, Les Szklanny wrote:
>     >     > IMHO you rely too much on the Mozilla spec, which is not
>     that great.
>     >     >
>     >     > Take for example the ability to early terminate the forEach
>     loop.
>     >      This
>     >     > feature is not in the Mozilla spec, but all other libraries
>     (Ext,
>     >     > JQuery, Prototype, MooTools) provide the ability to early
>     >     terminate forEach.
>     >     >
>     >     > In Dojo, however, I have to use dojo.some or dojo.every to
>     simulate
>     >     > breaking out of forEach, which is not intuitive.
>     >     >
>     >     > Les
>     >     >
>     >     > On Fri, Sep 4, 2009 at 8:44 AM, Peter E Higgins
>     >     <dante@... <mailto:dante@...>
>     <mailto:dante@... <mailto:dante@...>>
>     >     > <mailto:dante@... <mailto:dante@...>
>     <mailto:dante@... <mailto:dante@...>>>> wrote:
>     >     >
>     >     >     From:
>     >     >
>     >    
>     https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:forEach
>     >     >
>     >     >     ""
>     >     >     If a thisObject parameter is provided to forEach, it will be
>     >     used as the
>     >     >     this for each invocation of the callback. If it is not
>     >     provided, or is
>     >     >     null, the global object associated with callback is used
>     instead.
>     >     >     ""
>     >     >
>     >     >     You can access the original array as "arr" in your example,
>     >     just as you
>     >     >     would propose be 'this'.  In jQuery, 'this' is the item,
>     which
>     >     imo is
>     >     >     completely wrong. Easier to stick to generally accepted
>     specs.
>     >     >
>     >     >     Maybe I'm just missing the advantage to referring to your
>     >     original array
>     >     >     as 'this' over the third arg?
>     >     >
>     >     >     You code could also be written as:
>     >     >     var array = [1,2,3];
>     >     >     dojo.forEach(array, function(el, i){ }, array); // if
>     you must.
>     >     >
>     >     >     Regards,
>     >     >     Peter
>     >     >     > Why dojo.forEach default scope is dojo.global and not e.g.
>     >     the array
>     >     >     > or the element being processed?
>     >     >     >
>     >     >     > var array = [1,2,3];
>     >     >     > var scope = array;
>     >     >     > dojo.forEach(array, function(element, index, arr) {
>     >     >     >    debugger;
>     >     >     > }, scope);
>     >     >     >
>     >     >     > If I don't provide scope, 'this' object defaults to
>     >     dojo.global, which
>     >     >     > is not as useful.
>     >     >     >
>     >     >
>     >     >     --
>     >     >     Peter E Higgins
>     >     >     Dojo Project Lead : http://dojotoolkit.org
>     >     >
>     >     >     _______________________________________________
>     >     >     FAQ: http://dojotoolkit.org/support/faq
>     >     >     Book: http://docs.dojocampus.org
>     >     >     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>>
>     >     >     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >     >
>     >     >
>     >     >
>     >     >
>     >    
>     ------------------------------------------------------------------------
>     >     >
>     >     > _______________________________________________
>     >     > FAQ: http://dojotoolkit.org/support/faq
>     >     > Book: http://docs.dojocampus.org
>     >     > Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >
>     >     _______________________________________________
>     >     FAQ: http://dojotoolkit.org/support/faq
>     >     Book: http://docs.dojocampus.org
>     >     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >
>     >
>     >
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > FAQ: http://dojotoolkit.org/support/faq
>     > Book: http://docs.dojocampus.org
>     > Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>     _______________________________________________
>     FAQ: http://dojotoolkit.org/support/faq
>     Book: http://docs.dojocampus.org
>     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: dojo.forEach scope

by Eugene Lazutkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

First of all --- I am not bashing jQuery. And I am not in the business
of impressing others.

According to your numbers you had a 2x savings. If your payload consists
of something more than iterating through a single array, or you do it in
a tight loop, or in a fast event handling code (see the link I gave to
you earlier) this savings can be substantial.

Then again it all depends on tasks at hand --- if all you want is to add
two numbers it really doesn't matter how fast is the addition: 1ns or
100ms --- they both will be "instantaneous".

jQuery and Dojo target different markets, and I trust that they are both
successful in what they want to solve.

But I trust it is beyond the original point. If you want to re-formulate
it, please start a different thread.

Thanks,

Eugene Lazutkin
Dojo Toolkit, Committer
http://lazutkin.com/

On 09/04/2009 10:01 PM, Les Szklanny wrote:

> Here's my example, only 100,000 entries :)
>
> var a = [];
> for(var i = 0; i < 100000; ++i) a.push(i);
>
> console.time('dojo');
> dojo.forEach(a, function(){ return true; });
> console.timeEnd('dojo');
>
> console.time('jQuery');
> jQuery.each(a, function(){ return true; });
> console.timeEnd('jQuery');
>
> Results:
> dojo: 91ms
> jQuery: 208ms
>
> So I saved 117ms by using dojo.forEach on an array that has 100,000 entries.
> This is not an impressive number.
>
> On Fri, Sep 4, 2009 at 9:40 PM, Eugene Lazutkin
> <eugene.lazutkin@... <mailto:eugene.lazutkin@...>> wrote:
>
>     I didn't expect that you want me to test the obvious, but sure, I can
>     spare 2 minutes:
>
>     var a = [];
>     for(var i = 0; i < 1000000; ++i) a.push(i);
>     var dojoTime = new Date().getTime();
>     dojo.forEach(a, function(){ return true; });
>     dojoTime = new Date().getTime() - dojoTime;
>     var jqTime = new Date().getTime();
>     jQuery.each(a, function(){ return true; });
>     jqTime = new Date().getTime() - jqTime;
>     console.log("jQuery is ",
>      (jqTime / dojoTime).toFixed(2),
>      " slower than Dojo on iterating through arrays");
>
>     On my computer (FF/Linux 3.5) it prints:
>
>     jQuery is  2.93  slower than Dojo on iterating through arrays
>
>     I ran it 10 times and the number changes from time to time but the
>     result is > 2.7 on all attempts.
>
>     Google Chrome for Linux:
>
>     jQuery is 3.09 slower than Dojo on iterating through arrays
>
>     Opera 10.0 for Linux:
>
>     jQuery is 1.49 slower than Dojo on iterating through arrays
>
>     I think if we reverted to the native implementation, numbers would be
>     even more impressive. And dojox.lang.functional.array methods being more
>     lax are generally faster than the implementation in the Dojo base.
>
>     Thanks,
>
>     Eugene Lazutkin
>     Dojo Toolkit, Committer
>     http://lazutkin.com/
>
>     On 09/04/2009 09:10 PM, Les Szklanny wrote:
>     > Can you come up with an example that would back up your statement that
>     > there's any noticeable performance gain by not checking the return
>     value
>     > of the function?
>     >
>     > On Fri, Sep 4, 2009 at 8:48 PM, Eugene Lazutkin
>     > <eugene.lazutkin@... <mailto:eugene.lazutkin@...>
>     <mailto:eugene.lazutkin@...
>     <mailto:eugene.lazutkin@...>>> wrote:
>     >
>     >     12ms?
>     >    
>     http://lazutkin.com/blog/2008/mar/23/javascript-edp-and-0ms-timeouts/
>     >     --- to save on reading scroll down to the table.
>     >
>     >     And allow me to disagree politely with your performance vs.
>     convenience
>     >     assessment.
>     >
>     >     Thanks,
>     >
>     >     Eugene Lazutkin
>     >     Dojo Toolkit, Committer
>     >     http://lazutkin.com/
>     >
>     >     On 09/04/2009 08:04 PM, Les Szklanny wrote:
>     >     >>>> There is a reason why forEach doesn't support early
>     termination:
>     >     > performance. If it checks for an exit value, it will
>     penalize code
>     >     that
>     >     > doesn't need to terminate early.
>     >     >
>     >     > Performance degradation is negligible -  forEach is used for
>     >     > convenience, not for performance anyway.
>     >     >
>     >     > Run the code below at http://docs.dojocampus.org/dojo/NodeList
>     >     >
>     >     > var els = dojo.query('*');
>     >     > console.log(els.length)
>     >     > console.time('dojo');
>     >     > dojo.forEach(els, function(e){return true;});
>     >     > console.timeEnd('dojo');
>     >     > console.time('jQuery');
>     >     > jQuery.each(els, function(e){return true;});
>     >     > console.timeEnd('jQuery');
>     >     >
>     >     > http://docs.dojocampus.org/dojo/NodeList
>     >     >
>     >     > I see these results on my computer:
>     >     >
>     >     > elements: 1616
>     >     > dojo: 12ms
>     >     > jQuery: 12ms
>     >     >
>     >     > You will need to jQuerify the page:
>     >     >
>     >     > http://www.learningjquery.com/2006/12/jquerify-bookmarklet
>     >     >
>     >     >
>     >     >
>     >     > On Fri, Sep 4, 2009 at 6:43 PM, Eugene Lazutkin
>     >     > <eugene.lazutkin@...
>     <mailto:eugene.lazutkin@...> <mailto:eugene.lazutkin@...
>     <mailto:eugene.lazutkin@...>>
>     >     <mailto:eugene.lazutkin@...
>     <mailto:eugene.lazutkin@...>
>     >     <mailto:eugene.lazutkin@...
>     <mailto:eugene.lazutkin@...>>>> wrote:
>     >     >
>     >     >     Array functions are patterned after the array methods in the
>     >     upcoming
>     >     >     ECMA-262 5th edition. The idea was to provide shims for
>     >     methods of the
>     >     >     same name, or delegate to them if they are available. We
>     tried
>     >     to match
>     >     >     the behavior down to the argument list, and how the callback
>     >     is called.
>     >     >
>     >     >     (Sidenote: we need to provide the fallback to native
>     methods.
>     >     Right now
>     >     >     we don't do that because of the performance problems
>     with Firefox'
>     >     >     implementation.)
>     >     >
>     >     >     We used the Mozilla spec at that moment because that was
>     the only
>     >     >     codified thing available. Now, when the release candidate is
>     >     published,
>     >     >     we can revise our implementation to match it more closely.
>     >     Namely the
>     >     >     standard changed the default scope from the global to the
>     >     undefined (it
>     >     >     is true for other array methods). We need to update our
>     >     >     implementation too.
>     >     >
>     >     >     There is a reason why forEach doesn't support early
>     termination:
>     >     >     performance. If it checks for an exit value, it will
>     penalize
>     >     code that
>     >     >     doesn't need to terminate early. But I understand the
>     need for a
>     >     >     versatile iterating function, and I think it would be a good
>     >     candidate
>     >     >     for dojox.lang.functional methods. we can call it each()
>     just
>     >     like other
>     >     >     libraries do.
>     >     >
>     >     >     Thanks,
>     >     >
>     >     >     Eugene Lazutkin
>     >     >     Dojo Toolkit, Committer
>     >     >     http://lazutkin.com/
>     >     >
>     >     >     On 09/04/2009 09:12 AM, Les Szklanny wrote:
>     >     >     > IMHO you rely too much on the Mozilla spec, which is not
>     >     that great.
>     >     >     >
>     >     >     > Take for example the ability to early terminate the
>     forEach
>     >     loop.
>     >     >      This
>     >     >     > feature is not in the Mozilla spec, but all other
>     libraries
>     >     (Ext,
>     >     >     > JQuery, Prototype, MooTools) provide the ability to early
>     >     >     terminate forEach.
>     >     >     >
>     >     >     > In Dojo, however, I have to use dojo.some or dojo.every to
>     >     simulate
>     >     >     > breaking out of forEach, which is not intuitive.
>     >     >     >
>     >     >     > Les
>     >     >     >
>     >     >     > On Fri, Sep 4, 2009 at 8:44 AM, Peter E Higgins
>     >     >     <dante@... <mailto:dante@...>
>     <mailto:dante@... <mailto:dante@...>>
>     >     <mailto:dante@... <mailto:dante@...>
>     <mailto:dante@... <mailto:dante@...>>>
>     >     >     > <mailto:dante@...
>     <mailto:dante@...> <mailto:dante@...
>     <mailto:dante@...>>
>     >     <mailto:dante@... <mailto:dante@...>
>     <mailto:dante@... <mailto:dante@...>>>>> wrote:
>     >     >     >
>     >     >     >     From:
>     >     >     >
>     >     >
>     >    
>     https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:forEach
>     >     >     >
>     >     >     >     ""
>     >     >     >     If a thisObject parameter is provided to forEach,
>     it will be
>     >     >     used as the
>     >     >     >     this for each invocation of the callback. If it is not
>     >     >     provided, or is
>     >     >     >     null, the global object associated with callback
>     is used
>     >     instead.
>     >     >     >     ""
>     >     >     >
>     >     >     >     You can access the original array as "arr" in your
>     example,
>     >     >     just as you
>     >     >     >     would propose be 'this'.  In jQuery, 'this' is the
>     item,
>     >     which
>     >     >     imo is
>     >     >     >     completely wrong. Easier to stick to generally
>     accepted
>     >     specs.
>     >     >     >
>     >     >     >     Maybe I'm just missing the advantage to referring
>     to your
>     >     >     original array
>     >     >     >     as 'this' over the third arg?
>     >     >     >
>     >     >     >     You code could also be written as:
>     >     >     >     var array = [1,2,3];
>     >     >     >     dojo.forEach(array, function(el, i){ }, array); // if
>     >     you must.
>     >     >     >
>     >     >     >     Regards,
>     >     >     >     Peter
>     >     >     >     > Why dojo.forEach default scope is dojo.global
>     and not e.g.
>     >     >     the array
>     >     >     >     > or the element being processed?
>     >     >     >     >
>     >     >     >     > var array = [1,2,3];
>     >     >     >     > var scope = array;
>     >     >     >     > dojo.forEach(array, function(element, index, arr) {
>     >     >     >     >    debugger;
>     >     >     >     > }, scope);
>     >     >     >     >
>     >     >     >     > If I don't provide scope, 'this' object defaults to
>     >     >     dojo.global, which
>     >     >     >     > is not as useful.
>     >     >     >     >
>     >     >     >
>     >     >     >     --
>     >     >     >     Peter E Higgins
>     >     >     >     Dojo Project Lead : http://dojotoolkit.org
>     >     >     >
>     >     >     >     _______________________________________________
>     >     >     >     FAQ: http://dojotoolkit.org/support/faq
>     >     >     >     Book: http://docs.dojocampus.org
>     >     >     >     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>>
>     >     >     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>>>
>     >     >     >    
>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >     >     >
>     >     >     >
>     >     >     >
>     >     >     >
>     >     >
>     >    
>     ------------------------------------------------------------------------
>     >     >     >
>     >     >     > _______________________________________________
>     >     >     > FAQ: http://dojotoolkit.org/support/faq
>     >     >     > Book: http://docs.dojocampus.org
>     >     >     > Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>>
>     >     >     > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >     >
>     >     >     _______________________________________________
>     >     >     FAQ: http://dojotoolkit.org/support/faq
>     >     >     Book: http://docs.dojocampus.org
>     >     >     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>>
>     >     >     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >     >
>     >     >
>     >     >
>     >     >
>     >    
>     ------------------------------------------------------------------------
>     >     >
>     >     > _______________________________________________
>     >     > FAQ: http://dojotoolkit.org/support/faq
>     >     > Book: http://docs.dojocampus.org
>     >     > Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >
>     >     _______________________________________________
>     >     FAQ: http://dojotoolkit.org/support/faq
>     >     Book: http://docs.dojocampus.org
>     >     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     >     <mailto:Dojo-interest@...
>     <mailto:Dojo-interest@...>>
>     >     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >
>     >
>     >
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > FAQ: http://dojotoolkit.org/support/faq
>     > Book: http://docs.dojocampus.org
>     > Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>     _______________________________________________
>     FAQ: http://dojotoolkit.org/support/faq
>     Book: http://docs.dojocampus.org
>     Dojo-interest@...
>     <mailto:Dojo-interest@...>
>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest