diff --git a/docs/underscore.html b/docs/underscore.html index 976d41eba..1f4b86a94 100644 --- a/docs/underscore.html +++ b/docs/underscore.html @@ -1,4 +1,4 @@ - underscore.js

underscore.js

Underscore.js 1.4.1
+      underscore.js           

underscore.js

Underscore.js 1.4.2
 http://underscorejs.org
 (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
 Underscore may be freely distributed under the MIT license.
@@ -34,9 +34,10 @@
     exports._ = _;
   } else {
     root['_'] = _;
-  }

Current version.

  _.VERSION = '1.4.1';

Collection Functions

The cornerstone, an each implementation, aka forEach. + }

Current version.

  _.VERSION = '1.4.2';

Collection Functions

The cornerstone, an each implementation, aka forEach. Handles objects with the built-in forEach, arrays, and raw objects. Delegates to ECMAScript 5's native forEach if available.

  var each = _.each = _.forEach = function(obj, iterator, context) {
+    if (obj == null) return;
     if (nativeForEach && obj.forEach === nativeForEach) {
       obj.forEach(iterator, context);
     } else if (obj.length === +obj.length) {
@@ -53,6 +54,7 @@
   };

Return the results of applying the iterator to each element. Delegates to ECMAScript 5's native map if available.

  _.map = _.collect = function(obj, iterator, context) {
     var results = [];
+    if (obj == null) return results;
     if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
     each(obj, function(value, index, list) {
       results[results.length] = iterator.call(context, value, index, list);
@@ -61,6 +63,7 @@
   };

Reduce builds up a single result from a list of values, aka inject, or foldl. Delegates to ECMAScript 5's native reduce if available.

  _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
     var initial = arguments.length > 2;
+    if (obj == null) obj = [];
     if (nativeReduce && obj.reduce === nativeReduce) {
       if (context) iterator = _.bind(iterator, context);
       return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
@@ -78,6 +81,7 @@
   };

The right-associative version of reduce, also known as foldr. Delegates to ECMAScript 5's native reduceRight if available.

  _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
     var initial = arguments.length > 2;
+    if (obj == null) obj = [];
     if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
       if (context) iterator = _.bind(iterator, context);
       return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
@@ -111,6 +115,7 @@
 Delegates to ECMAScript 5's native filter if available.
 Aliased as select.

  _.filter = _.select = function(obj, iterator, context) {
     var results = [];
+    if (obj == null) return results;
     if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
     each(obj, function(value, index, list) {
       if (iterator.call(context, value, index, list)) results[results.length] = value;
@@ -118,6 +123,7 @@
     return results;
   };

Return all the elements for which a truth test fails.

  _.reject = function(obj, iterator, context) {
     var results = [];
+    if (obj == null) return results;
     each(obj, function(value, index, list) {
       if (!iterator.call(context, value, index, list)) results[results.length] = value;
     });
@@ -127,6 +133,7 @@
 Aliased as all.

  _.every = _.all = function(obj, iterator, context) {
     iterator || (iterator = _.identity);
     var result = true;
+    if (obj == null) return result;
     if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
     each(obj, function(value, index, list) {
       if (!(result = result && iterator.call(context, value, index, list))) return breaker;
@@ -137,6 +144,7 @@
 Aliased as any.

  var any = _.some = _.any = function(obj, iterator, context) {
     iterator || (iterator = _.identity);
     var result = false;
+    if (obj == null) return result;
     if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
     each(obj, function(value, index, list) {
       if (result || (result = iterator.call(context, value, index, list))) return breaker;
@@ -145,6 +153,7 @@
   };

Determine if the array or object contains a given value (using ===). Aliased as include.

  _.contains = _.include = function(obj, target) {
     var found = false;
+    if (obj == null) return found;
     if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
     found = any(obj, function(value) {
       return value === target;
@@ -346,6 +355,7 @@
 Delegates to ECMAScript 5's native indexOf if available.
 If the array is large and already in sort order, pass true
 for isSorted to use binary search.

  _.indexOf = function(array, item, isSorted) {
+    if (array == null) return -1;
     var i = 0, l = array.length;
     if (isSorted) {
       if (typeof isSorted == 'number') {
@@ -359,6 +369,7 @@
     for (; i < l; i++) if (array[i] === item) return i;
     return -1;
   };

Delegates to ECMAScript 5's native lastIndexOf if available.

  _.lastIndexOf = function(array, item, from) {
+    if (array == null) return -1;
     var hasIndex = from != null;
     if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
       return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
diff --git a/index.html b/index.html
index dec084ce8..71b1f5a36 100644
--- a/index.html
+++ b/index.html
@@ -179,7 +179,7 @@