diff --git a/index.html b/index.html
index b7a368b34..5df3e296d 100644
--- a/index.html
+++ b/index.html
@@ -113,11 +113,11 @@
@@ -1067,6 +1067,22 @@ _([1, 2, 3]).value();
Change Log
+
+
+ New implementations of isArray, isDate, isFunction,
+ isNumber, isRegExp, and isString, thanks to
+ a suggestion from
+ Robert Kieffer.
+ Instead of doing Object#toString
+ comparisons, they now check for expected properties, which is less safe,
+ but more than an order of magnitude faster. Most other Underscore
+ functions saw minor speed improvements as a result.
+ Evgeniy Dolzhenko
+ contributed _.tap,
+ similar to Ruby 1.9's,
+ which is handy for injecting side effects (like logging) into chained calls.
+
+
Added an _.isArguments function. Lots of little safety checks
diff --git a/underscore-min.js b/underscore-min.js
index 4360e355a..ad147a93b 100644
--- a/underscore-min.js
+++ b/underscore-min.js
@@ -1,16 +1,17 @@
-(function(){var j=this,p=j._,i=function(a){this._wrapped=a},o=typeof StopIteration!=="undefined"?StopIteration:"__break__",b=j._=function(a){return new i(a)};if(typeof exports!=="undefined")exports._=b;var l=Array.prototype.slice,q=Array.prototype.unshift,r=Object.prototype.toString,s=Object.prototype.hasOwnProperty,t=Object.prototype.propertyIsEnumerable;b.VERSION="0.5.1";b.each=function(a,c,d){try{if(a.forEach)a.forEach(c,d);else if(b.isArray(a)||b.isArguments(a))for(var e=0,f=a.length;e=e.computed&&(e={value:f,computed:g})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);var e={computed:Infinity};b.each(a,function(f,g,h){g=c?c.call(d,f,g,h):f;gf?1:0}),"value")};b.sortedIndex=function(a,c,d){d=d||b.identity;for(var e=0,f=a.length;e>1;d(a[g])f?1:0}),"value")};b.sortedIndex=function(a,c,d){d=d||b.identity;for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.zip=function(){for(var a=b.toArray(arguments),c=b.max(b.pluck(a,"length")),d=new Array(c),e=0;e0?f-c:c-f)>=0)return e;e[g++]=f}};b.bind=function(a,c){var d=b.rest(arguments,2);return function(){return a.apply(c||j,d.concat(b.toArray(arguments)))}};b.bindAll=function(a){var c=b.rest(arguments);if(c.length==0)c=b.functions(a);b.each(c,function(d){a[d]=b.bind(a[d],
a)});return a};b.delay=function(a,c){var d=b.rest(arguments,2);return setTimeout(function(){return a.apply(a,d)},c)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(b.rest(arguments)))};b.wrap=function(a,c){return function(){var d=[a].concat(b.toArray(arguments));return c.apply(c,d)}};b.compose=function(){var a=b.toArray(arguments);return function(){for(var c=b.toArray(arguments),d=a.length-1;d>=0;d--)c=[a[d].apply(this,c)];return c[0]}};b.keys=function(a){if(b.isArray(a))return b.range(0,
-a.length);var c=[];for(var d in a)s.call(a,d)&&c.push(d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=function(a){return b.select(b.keys(a),function(c){return b.isFunction(a[c])}).sort()};b.extend=function(a,c){for(var d in c)a[d]=c[d];return a};b.clone=function(a){if(b.isArray(a))return a.slice(0);return b.extend({},a)};b.isEqual=function(a,c){if(a===c)return true;var d=typeof a;if(d!=typeof c)return false;if(a==c)return true;if(!a&&c||a&&!c)return false;if(a.isEqual)return a.isEqual(c);
-if(b.isDate(a)&&b.isDate(c))return a.getTime()===c.getTime();if(b.isNaN(a)&&b.isNaN(c))return true;if(b.isRegExp(a)&&b.isRegExp(c))return a.source===c.source&&a.global===c.global&&a.ignoreCase===c.ignoreCase&&a.multiline===c.multiline;if(d!=="object")return false;if(a.length&&a.length!==c.length)return false;d=b.keys(a);var e=b.keys(c);if(d.length!=e.length)return false;for(var f in a)if(!b.isEqual(a[f],c[f]))return false;return true};b.isEmpty=function(a){return b.keys(a).length==0};b.isElement=
-function(a){return!!(a&&a.nodeType==1)};b.isArguments=function(a){return a&&b.isNumber(a.length)&&!b.isArray(a)&&!t.call(a,"length")};b.isNaN=function(a){return b.isNumber(a)&&isNaN(a)};b.isNull=function(a){return a===null};b.isUndefined=function(a){return typeof a=="undefined"};for(var m=["Array","Date","Function","Number","RegExp","String"],k=0,u=m.length;k)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return c?a(c):a};b.forEach=b.each;b.foldl=b.inject=
-b.reduce;b.foldr=b.reduceRight;b.filter=b.select;b.every=b.all;b.some=b.any;b.head=b.first;b.tail=b.rest;b.methods=b.functions;var n=function(a,c){return c?b(a).chain():a};b.each(b.functions(b),function(a){var c=b[a];i.prototype[a]=function(){q.call(arguments,this._wrapped);return n(c.apply(b,arguments),this._chain)}});b.each(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var c=Array.prototype[a];i.prototype[a]=function(){c.apply(this._wrapped,arguments);return n(this._wrapped,
-this._chain)}});b.each(["concat","join","slice"],function(a){var c=Array.prototype[a];i.prototype[a]=function(){return n(c.apply(this._wrapped,arguments),this._chain)}});i.prototype.chain=function(){this._chain=true;return this};i.prototype.value=function(){return this._wrapped}})();
+a.length);var c=[];for(var d in a)q.call(a,d)&&c.push(d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=function(a){return b.select(b.keys(a),function(c){return b.isFunction(a[c])}).sort()};b.extend=function(a,c){for(var d in c)a[d]=c[d];return a};b.clone=function(a){if(b.isArray(a))return a.slice(0);return b.extend({},a)};b.tap=function(a,c){c(a);return a};b.isEqual=function(a,c){if(a===c)return true;var d=typeof a;if(d!=typeof c)return false;if(a==c)return true;if(!a&&c||
+a&&!c)return false;if(a.isEqual)return a.isEqual(c);if(b.isDate(a)&&b.isDate(c))return a.getTime()===c.getTime();if(b.isNaN(a)&&b.isNaN(c))return true;if(b.isRegExp(a)&&b.isRegExp(c))return a.source===c.source&&a.global===c.global&&a.ignoreCase===c.ignoreCase&&a.multiline===c.multiline;if(d!=="object")return false;if(a.length&&a.length!==c.length)return false;d=b.keys(a);var e=b.keys(c);if(d.length!=e.length)return false;for(var f in a)if(!b.isEqual(a[f],c[f]))return false;return true};b.isEmpty=
+function(a){return b.keys(a).length==0};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=function(a){return a&&a.concat&&a.unshift};b.isArguments=function(a){return a&&b.isNumber(a.length)&&!b.isArray(a)&&!r.call(a,"length")};b.isFunction=function(a){return a&&a.constructor&&a.call&&a.apply};b.isString=function(a){return a===""||a&&a.charCodeAt&&a.substr};b.isNumber=function(a){return p.call(a)==="[object Number]"};b.isDate=function(a){return a&&a.getTimezoneOffset&&a.setUTCFullYear};
+b.isRegExp=function(a){return a&&a.test&&a.exec&&(a.ignoreCase||a.ignoreCase===false)};b.isNaN=function(a){return b.isNumber(a)&&isNaN(a)};b.isNull=function(a){return a===null};b.isUndefined=function(a){return typeof a=="undefined"};b.noConflict=function(){j._=n;return this};b.identity=function(a){return a};b.breakLoop=function(){throw m;};var s=0;b.uniqueId=function(a){var c=s++;return a?a+c:c};b.template=function(a,c){a=new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+
+a.replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return c?a(c):a};b.forEach=b.each;b.foldl=b.inject=b.reduce;b.foldr=b.reduceRight;b.filter=b.select;b.every=b.all;b.some=b.any;b.head=b.first;b.tail=b.rest;b.methods=b.functions;var l=function(a,c){return c?b(a).chain():a};b.each(b.functions(b),function(a){var c=b[a];i.prototype[a]=
+function(){o.call(arguments,this._wrapped);return l(c.apply(b,arguments),this._chain)}});b.each(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var c=Array.prototype[a];i.prototype[a]=function(){c.apply(this._wrapped,arguments);return l(this._wrapped,this._chain)}});b.each(["concat","join","slice"],function(a){var c=Array.prototype[a];i.prototype[a]=function(){return l(c.apply(this._wrapped,arguments),this._chain)}});i.prototype.chain=function(){this._chain=true;return this};
+i.prototype.value=function(){return this._wrapped}})();
diff --git a/underscore.js b/underscore.js
index d986c6543..b51395cdb 100644
--- a/underscore.js
+++ b/underscore.js
@@ -8,7 +8,7 @@
(function() {
- /*------------------------- Baseline setup ---------------------------------*/
+ // ------------------------- Baseline setup ---------------------------------
// Establish the root object, "window" in the browser, or "global" on the server.
var root = this;
@@ -38,9 +38,9 @@
propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
// Current version.
- _.VERSION = '0.5.1';
+ _.VERSION = '0.5.2';
- /*------------------------ Collection Functions: ---------------------------*/
+ // ------------------------ Collection Functions: ---------------------------
// The cornerstone, an each implementation.
// Handles objects implementing forEach, arrays, and raw objects.
@@ -234,7 +234,7 @@
return _.toArray(obj).length;
};
- /*-------------------------- Array Functions: ------------------------------*/
+ // -------------------------- Array Functions: ------------------------------
// Get the first element of an array. Passing "n" will return the first N
// values in the array. Aliased as "head". The "guard" check allows it to work
@@ -340,7 +340,7 @@
}
};
- /* ----------------------- Function Functions: -----------------------------*/
+ // ----------------------- Function Functions: ------------------------------
// Create a function bound to a given object (assigning 'this', and arguments,
// optionally). Binding with arguments is also known as 'curry'.
@@ -396,7 +396,7 @@
};
};
- /* ------------------------- Object Functions: ---------------------------- */
+ // ------------------------- Object Functions: ------------------------------
// Retrieve the names of an object's properties.
_.keys = function(obj) {
@@ -532,7 +532,7 @@
return typeof obj == 'undefined';
};
- /* -------------------------- Utility Functions: -------------------------- */
+ // -------------------------- Utility Functions: ----------------------------
// Run Underscore.js in noConflict mode, returning the '_' variable to its
// previous owner. Returns a reference to the Underscore object.
@@ -577,7 +577,7 @@
return data ? fn(data) : fn;
};
- /*------------------------------- Aliases ----------------------------------*/
+ // ------------------------------- Aliases ----------------------------------
_.forEach = _.each;
_.foldl = _.inject = _.reduce;
@@ -589,7 +589,7 @@
_.tail = _.rest;
_.methods = _.functions;
- /*------------------------ Setup the OOP Wrapper: --------------------------*/
+ // ------------------------ Setup the OOP Wrapper: --------------------------
// Helper function to continue chaining intermediate results.
var result = function(obj, chain) {