Skip to content
This repository
Browse code

Undefined check in can.each.

  • Loading branch information...
commit c3016bc9d7075e5a31cc37576d944d9734457307 1 parent 017404a
authored May 17, 2012

Showing 1 changed file with 12 additions and 10 deletions. Show diff stats Hide diff stats

  1. 22  util/array/each.js
22  util/array/each.js
... ...
@@ -1,16 +1,18 @@
1 1
 steal(function(){
2 2
 	can.each = function(elements, callback) {
3 3
 		var i = 0, key;
4  
-		if (typeof  elements.length == 'number' && elements.pop) {
5  
-			elements.attr && elements.attr('length');
6  
-			for(var len = elements.length; i < len; i++) {
7  
-				if(callback(elements[i], i, elements) === false) return elements;
8  
-			}
9  
-		} else {
10  
-			for(key in elements) {
11  
-				if(callback(elements[key], key) === false) return elements;
12  
-			}
13  
-		}
  4
+    if ( elements ) {
  5
+      if (typeof  elements.length == 'number' && elements.pop) {
  6
+        elements.attr && elements.attr('length');
  7
+        for(var len = elements.length; i < len; i++) {
  8
+          if(callback(elements[i], i, elements) === false) return elements;
  9
+        }
  10
+      } else {
  11
+        for(key in elements) {
  12
+          if(callback(elements[key], key) === false) return elements;
  13
+        }
  14
+      }
  15
+    }
14 16
 		return elements;
15 17
 	}
16 18
 })

0 notes on commit c3016bc

Please sign in to comment.
Something went wrong with that request. Please try again.