Skip to content

Commit

Permalink
use call to bind the current array element to this
Browse files Browse the repository at this point in the history
  • Loading branch information
james2doyle committed Nov 5, 2014
1 parent d250300 commit 31c43c9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build/parts/each.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$.each = function(arr, callback) {
var i = 0, l = arr.length;
for(; i < l; ++i) {
callback(i, arr[i]);
callback.call(arr[i], i, arr[i]);
}
return this;
};
2 changes: 1 addition & 1 deletion ki.extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$.each = function(arr, callback) {
var i = 0, l = arr.length;
for(; i < l; ++i) {
callback(i, arr[i]);
callback.call(arr[i], i, arr[i]);
}
return this;
};
Expand Down
2 changes: 1 addition & 1 deletion ki.extend.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/each-arrays/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
document.addEventListener('DOMContentLoaded', function() {
var arr = ['a','b','c'];
var newarr = $.each(arr, function(index, elem){
log(index, elem);
log(index, elem, this);
}).map(arr, function(item){
return item + 'a';
});
Expand Down

0 comments on commit 31c43c9

Please sign in to comment.