[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-28 Thread diogobaeder
H... nice, I didn't know of this project "vice-versa"... it covers my needs, indeed... :-) Thanks, Andrea! Diogo On May 26, 12:54 pm, Andrea Giammarchi wrote: > I think I have no problems with vice-versa :D > > I use jQuery mainy for Sizzle and some tricky method so I would implement > d

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-26 Thread Andrea Giammarchi
I think I have no problems with vice-versa :D I use jQuery mainy for Sizzle and some tricky method so I would implement directly Array.forEach if not present, rather than another jQuery method which aim is to clone specs ( so it should not be jQuery method ) You can simply include only this file

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-26 Thread diogobaeder
Hi, Andrea, sorry for being late in my answer... :-( Thanks for the explanation! Well, in my opinion, we would better stick with MDC implementation in JS, because this way we can tell exactly what the code does to people who want to know what it is, and because it has passed by a whole lot of tes

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-23 Thread Andrea Giammarchi
Ok. This is the point. Array.forEach is mainly used with non Array objects. This is because with an Array we'll simply use a.forEach() rather than Array.forEach(a). The most common case about Array.forEach is with HTMLCollection, a live object. Array.forEach(document.getElementsByTagName("div"),

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-22 Thread diogobaeder
Andrea, I don't think I got your point with live objects and forEach... could you please give an example where the basic implementation (as shown by Mozilla) would not be adequate? Thanks! Diogo On May 22, 5:29 am, Andrea Giammarchi wrote: > Ok, MDC specs do not consider the length, so the

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-22 Thread Andrea Giammarchi
Ok, MDC specs do not consider the length, so the most close is this Array.forEach = Array.forEach || function(obj, callback, scope){ for(var i = 0, length = obj.length; i < length; ++i){ if(i in obj)callback.call(scope, obj[i], i, obj); }; }; Sorry for that

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-22 Thread Andrea Giammarchi
To be honest I wrote something a bit redundant, this one is better if you want to use the length. Array.forEach = Array.forEach || function(obj, callback, scope){ for(var i = 0; i < obj.length; ++i){ if(i in obj) callback.call(scope, obj[i], i, obj); }; }; even more sim

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-21 Thread Andrea Giammarchi
Actually, the main usage of Array.forEach is with non Array, like live objects. Since with DOM is easy to remove a node and the result of the live object could be completely changed, do you prefere 100 useless if I in obj or just a loop brek thanks to changed length? Dunno which is faster and the p

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-21 Thread Amita Dhainje
yes it is working fine in ie8 --- On Thu, 21/5/09, diogobaeder wrote: From: diogobaeder Subject: [jquery-dev] Re: $.each and JS 1.6's forEach To: "jQuery Development" Date: Thursday, 21 May, 2009, 8:41 PM Hmmm... close, I agree, but still not cross-browser compliant... ;-)

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-21 Thread Robert Katić
There is no need to take in consideration eventual length updates; that slows considerably, and it is not garanted in any/each native implementation: https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Array/ForEach On May 21, 5:39 pm, Andrea Giammarchi wrote: > IE8? o

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-21 Thread Andrea Giammarchi
IE8? obviously no, how can you pretend a browser that implemented defineProperty only for Window and DOM can be "so advanced" with other native constructors? :D Anyway, the most legacy like forEach is something like this: Array.forEach = Array.forEach || function(obj, callback, scope){ for(va

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-21 Thread diogobaeder
Hmmm... close, I agree, but still not cross-browser compliant... ;-) Question: does IE8 support these methods (abstract and instance) natively? Diogo On May 20, 3:37 pm, Andrea Giammarchi wrote: > P.S. Array.forEach is standard in FireFox and some other browser, so it is > still native one >

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-20 Thread Andrea Giammarchi
P.S. Array.forEach is standard in FireFox and some other browser, so it is still native one On Wed, May 20, 2009 at 7:36 PM, Andrea Giammarchi < andrea.giammar...@gmail.com> wrote: > jQuery.forEach = Array.forEach || function(){ ... } > > now you are close to vice-versa logic, where you can simpl

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-20 Thread Andrea Giammarchi
jQuery.forEach = Array.forEach || function(){ ... } now you are close to vice-versa logic, where you can simply use Array.forEach with every array like variable, DOM colelctions included ;-) On Wed, May 20, 2009 at 6:39 PM, diogobaeder wrote: > > Hmmm... almost there, in my opinion, Andrea... I

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-20 Thread diogobaeder
Hmmm... almost there, in my opinion, Andrea... I think it could be used in the main jQuery object (singleton), also, to minimize browser dependance, if the user wants to use it with normal Array objects... like: jQuery.forEach(myArrayObject, , myCallback, myContext); What do you think? This way,

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-19 Thread Andrea Giammarchi
JQuery.fn.forEach = Array.prototype.forEach || function(){ ... }; easy? :-) On May 20, 2009 3:07 AM, "diogobaeder" wrote: Matt, I think your approach is usefull only if one wants to create a new jQuery method... because checking everytime if forEach method exists is not easily maintainable...

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-19 Thread diogobaeder
Matt, I think your approach is usefull only if one wants to create a new jQuery method... because checking everytime if forEach method exists is not easily maintainable... Maybe it could be a $.forEach, applying the Mozilla implementation if the browser doesn't support the method... what do you

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-19 Thread Matt Kruse
On May 19, 9:19 am, diogobaeder wrote: > Brainstorming: what about a $.each2 method, to avoid messing with the > original signature (name + parameters), but using > Array.prototype.forEach? Why not just call Array.prototype.forEach in your code if it exists? Matt Kruse --~--~-~--~

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-19 Thread diogobaeder
Hmmm... interesting... thanks, Andrea! Brainstorming: what about a $.each2 method, to avoid messing with the original signature (name + parameters), but using Array.prototype.forEach? Diogo On May 18, 11:29 am, Andrea Giammarchi wrote: > it's not about the name, it's about arguments plus ret

[jquery-dev] Re: $.each and JS 1.6's forEach

2009-05-18 Thread Andrea Giammarchi
it's not about the name, it's about arguments plus returned value. I do not know why John decided at that time to make jQuery.fn.each "a bit redundant" avoiding JS 1.6 forEach MDC specs and limiting performances boost via native callback ( it would be a double wrap, one to return the jQuery object