Skip to content

Make forEach have the same interface as Array.prototype.forEach#1

Open
doug65536 wants to merge 1 commit intogeisbruch:masterfrom
doug65536:forEachThisArg
Open

Make forEach have the same interface as Array.prototype.forEach#1
doug65536 wants to merge 1 commit intogeisbruch:masterfrom
doug65536:forEachThisArg

Conversation

@doug65536
Copy link

I have extended forEach to have the same behavior as the "real" Array.prototype.forEach.

  • The real one passes the collection as an argument as the third parameter to the callback, useful for avoiding unnecessary closure to get the collection.
  • The real one accepts a second parameter, used as the 'this' value in the callback. Also useful for avoiding unnecessary closure, and avoids having to setup var self = this.

This is almost a completely non-breaking change. The only tiny difference is, the callback is called with one additional argument. Callers should be expecting that argument in a forEach callback, that looks and acts just like Array#forEach, anyway.

The test is pretty exhaustive as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant