Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Undefined check in can.each.

  • Loading branch information...
commit c3016bc9d7075e5a31cc37576d944d9734457307 1 parent 017404a
Ralph Holzmann authored
Showing with 12 additions and 10 deletions.
  1. +12 −10 util/array/each.js
View
22 util/array/each.js
@@ -1,16 +1,18 @@
steal(function(){
can.each = function(elements, callback) {
var i = 0, key;
- 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(elements[i], i, elements) === false) return elements;
+ }
+ } else {
+ for(key in elements) {
+ if(callback(elements[key], key) === false) return elements;
+ }
+ }
+ }
return elements;
}
})
Please sign in to comment.
Something went wrong with that request. Please try again.