From a6578068d212e51aa1988eb7b454ab4a55fd6217 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Fri, 19 Mar 2010 10:07:21 -0400 Subject: [PATCH] Underscore 1.0.1 -- bugfix release for _.isEqual --- index.html | 10 ++++++++-- package.json | 2 +- test/objects.js | 1 + underscore-min.js | 4 ++-- underscore.js | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 59cae8491..f46a6b9a5 100644 --- a/index.html +++ b/index.html @@ -111,11 +111,11 @@

Downloads (Right-click, and u

- + - +
Development Version (1.0.0)Development Version (1.0.1) 25kb, Uncompressed with Comments
Production Version (1.0.0)Production Version (1.0.1) 2.5kb, Packed and Gzipped
@@ -1136,6 +1136,12 @@

Links & Suggested Reading

Change Log

+

+ 1.0.1
+ Bugfix for _.isEqual, when comparing two objects with the same + number of undefined keys, but with different names. +

+

1.0.0
Things have been stable for many months now, so Underscore is now diff --git a/package.json b/package.json index e9fda74e8..197a47660 100644 --- a/package.json +++ b/package.json @@ -7,5 +7,5 @@ "contributors" : [], "dependencies" : [], "lib" : ".", - "version" : "1.0.0" + "version" : "1.0.1" } diff --git a/test/objects.js b/test/objects.js index a30b30e94..6b52fb2c3 100644 --- a/test/objects.js +++ b/test/objects.js @@ -58,6 +58,7 @@ $(document).ready(function() { ok(_.isEqual(new Date(100), new Date(100)), 'identical dates are equal'); ok(_.isEqual((/hello/ig), (/hello/ig)), 'identical regexes are equal'); ok(!_.isEqual(null, [1]), 'a falsy is never equal to a truthy'); + ok(!_.isEqual({x: 1, y: undefined}, {x: 1, z: 2}), 'object with the same number of undefined keys are not equal'); }); test("objects: isEmpty", function() { diff --git a/underscore-min.js b/underscore-min.js index e3b1eb37d..189b2ab27 100644 --- a/underscore-min.js +++ b/underscore-min.js @@ -1,5 +1,5 @@ (function(){var n=this,A=n._,r=typeof StopIteration!=="undefined"?StopIteration:"__break__",B=function(a){return a.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1")},j=Array.prototype,l=Object.prototype,o=j.slice,C=j.unshift,D=l.toString,p=l.hasOwnProperty,E=l.propertyIsEnumerable,s=j.forEach,t=j.map,u=j.reduce,v=j.reduceRight,w=j.filter,x=j.every,y=j.some,m=j.indexOf,z=j.lastIndexOf;l=Array.isArray;var F=Object.keys,b=function(a){return new k(a)};if(typeof exports!=="undefined")exports._=b;n._=b;b.VERSION= -"1.0.0";var i=b.forEach=function(a,c,d){try{if(s&&a.forEach===s)a.forEach(c,d);else if(b.isNumber(a.length))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};i(a,function(f,g,h){g=c?c.call(d,f,g,h):f;g0?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||{},d.concat(b.toArray(arguments)))}};b.bindAll=function(a){var c=b.rest(arguments);if(c.length==0)c=b.functions(a);i(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=F||function(a){if(b.isArray(a))return b.range(0, a.length);var c=[];for(var d in a)p.call(a,d)&&c.push(d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=function(a){return b.filter(b.keys(a),function(c){return b.isFunction(a[c])}).sort()};b.extend=function(a){i(b.rest(arguments),function(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; +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(!(f in c)||!b.isEqual(a[f],c[f]))return false; return true};b.isEmpty=function(a){if(b.isArray(a))return a.length===0;for(var c in a)if(p.call(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=l||function(a){return!!(a&&a.concat&&a.unshift)};b.isArguments=function(a){return a&&b.isNumber(a.length)&&!a.concat&&!a.substr&&!a.apply&&!E.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 a=== +a||D.call(a)==="[object Number]"};b.isBoolean=function(a){return a===true||a===false};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(){n._=A;return this};b.identity=function(a){return a};b.times=function(a,c,d){for(var e= 0;e",interpolate:/<%=(.+?)%>/g};b.template=function(a,c){var d=b.templateSettings,e=new RegExp("'(?=[^"+d.end.substr(0,1)+"]*"+B(d.end)+")","g");a=new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+a.replace(/[\r\t\n]/g," ").replace(e,"\t").split("'").join("\\'").split("\t").join("'").replace(d.interpolate, diff --git a/underscore.js b/underscore.js index 52ce4f771..9a6c02f65 100644 --- a/underscore.js +++ b/underscore.js @@ -55,7 +55,7 @@ root._ = _; // Current version. - _.VERSION = '1.0.0'; + _.VERSION = '1.0.1'; // ------------------------ Collection Functions: --------------------------- @@ -485,7 +485,7 @@ // Different object sizes? if (aKeys.length != bKeys.length) return false; // Recursive comparison of contents. - for (var key in a) if (!_.isEqual(a[key], b[key])) return false; + for (var key in a) if (!(key in b) || !_.isEqual(a[key], b[key])) return false; return true; };