Skip to content

Commit

Permalink
Allow context to be passed as a third argument to can.each.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Holzmann committed Jun 2, 2012
1 parent 19c9ca0 commit bbd2ad5
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions util/array/each.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
steal(function(){
can.each = function(elements, callback) {
can.each = function( elements, callback, context ) {
var i = 0, key;
if ( elements ) {
if (typeof elements.length == 'number' && elements.pop) {
elements.attr && elements.attr('length');
for(var len = elements.length; i < len; i++) {
if(callback(elements[i], i, elements) === false) return elements;
}
} else {
for(key in elements) {
if(callback(elements[key], key) === false) return elements;
}
}
}
if ( elements ) {
if ( typeof elements.length == 'number' && elements.pop ) {
elements.attr && elements.attr('length');
for ( var len = elements.length; i < len; i++ ) {
if ( callback.call( context, elements[i], i, elements ) === false ) {
break;
}
}
} else {
for ( key in elements ) {
if ( callback.call( context, elements[key], key ) === false ) {
break;
}
}
}
}
return elements;
}
})
});

0 comments on commit bbd2ad5

Please sign in to comment.