On Feb 16, 7:29 am, Yaffle <vic99...@yandex.ru> wrote:
> Hello,
>
> Why with JavaScript <= 1.5,  Array.prototype._each method doesn't use
> a context object
>
> like
>
> Array.prototype.forEach(callback[, thisObject]) in JavaScript 1.6
>
> or
>
> Enumerable.prototype.each(iterator[, context]) ?
>
> thank you.

Because `Array.prototype._each` (defined by Prototype.js) is bound to
custom `each` implementation when native `Array.prototype.forEach` is
unavailable (e.g. in older versions of Firefox). That custom
implementation currently looks like:

function each(iterator) {
  for (var i = 0, length = this.length; i < length; i++)
    iterator(this[i]);
}

while, to be consistent with `forEach`, it would need to look like:

function each(iterator, context) {
  for (var i = 0, length = this.length; i < length; i++)
    iterator.call(context, this[i], i, this);
}

--
kangax
--~--~---------~--~----~------------~-------~--~----~
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 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to