Underscore 0.5.8, with collection functions that once again work on NodeLists and HTMLCollections

This commit is contained in:
Jeremy Ashkenas
2010-01-28 00:55:41 -05:00
parent 21f37e43a1
commit 5b5ee87c7a
4 changed files with 27 additions and 12 deletions

View File

@@ -38,7 +38,7 @@
propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
// Current version.
_.VERSION = '0.5.7';
_.VERSION = '0.5.8';
// ------------------------ Collection Functions: ---------------------------
@@ -49,7 +49,7 @@
try {
if (obj.forEach) {
obj.forEach(iterator, context);
} else if (_.isArray(obj) || _.isArguments(obj)) {
} else if (_.isNumber(obj.length)) {
for (var i=0, l=obj.length; i<l; i++) iterator.call(context, obj[i], i, obj);
} else {
var keys = _.keys(obj), l = keys.length;
@@ -152,7 +152,7 @@
// Determine if a given value is included in the array or object,
// based on '==='.
_.include = function(obj, target) {
if (_.isArray(obj)) return _.indexOf(obj, target) != -1;
if (obj && _.isFunction(obj.indexOf)) return _.indexOf(obj, target) != -1;
var found = false;
_.each(obj, function(value) {
if (found = value === target) _.breakLoop();
@@ -400,7 +400,7 @@
// Retrieve the names of an object's properties.
_.keys = function(obj) {
if(_.isArray(obj)) return _.range(0, obj.length);
if (_.isArray(obj)) return _.range(0, obj.length);
var keys = [];
for (var key in obj) if (hasOwnProperty.call(obj, key)) keys.push(key);
return keys;