Permalink
Browse files

模拟相对正确的 Array.prototype.forEach

  • Loading branch information...
1 parent 5316d8d commit 4dd1a1bd8ea094e2dceaf964ad3eae6a6d8f77ef @penJunTan penJunTan committed Apr 17, 2014
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/index.js
View
4 lib/index.js
@@ -41,8 +41,8 @@ if (typeof window !== 'undefined') {
};
}
if (!Array.prototype.forEach) {
- Array.prototype.forEach = function (fn) {
- for (var i = 0; i < this.length; i++) fn(this[i], i, this);
+ Array.prototype.forEach = function (fn, scope) {
+ for (var i = 0; i < this.length; i++) fn.call(scope, this[i], i, this);
};
}
if(!String.prototype.trim){

0 comments on commit 4dd1a1b

Please sign in to comment.