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 <[email protected]>
wrote:
> 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(var
>         length = obj.length,
>         i = 0;
>         i < length;
>         ++i
>     ){
>         if(i in obj){ // forEach does not loop over undefined indexes
>             callback.call(scope, obj[i], i, obj);
>
>             // the callback could have changed the Array/collection
>             length = obj.length;
>         };
>     };
>
> };
>
> Best regards,
> Andrea Giammarchi
>
> On Thu, May 21, 2009 at 4:11 PM, diogobaeder <[email protected]> wrote:
>
> > 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 <[email protected]>
> > wrote:
> > > 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 <
>
> > > [email protected]> wrote:
> > > > 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 <[email protected]
> > >wrote:
>
> > > >> 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, the client code can use it both with
> > > >> Array objects and jQuery wrapped DOM objects...
>
> > > >> Diogo
>
> > > >> On May 20, 3:35 am, Andrea Giammarchi <[email protected]>
> > > >> wrote:
> > > >> > JQuery.fn.forEach = Array.prototype.forEach || function(){ ... };
> >  easy?
> > > >> :-)
>
> > > >> > On May 20, 2009 3:07 AM, "diogobaeder" <[email protected]>
> > 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...
>
> > > >> > Maybe it could be a $.forEach, applying the Mozilla implementation
> > if
> > > >> > the browser doesn't support the method... what do you guys think of
> > > >> > it?
>
> > > >> > Diogo
>
> > > >> > On May 19, 11:29 am, Matt Kruse <[email protected]> wrote: >
> > On
> > > >> May
> > > >> > 19, 9:19 am, diogobaede...
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to