From d77c9d3fca2925375bcb1d91355fe0244491e002 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 26 Mar 2013 20:46:02 -0700 Subject: [PATCH] Ensure `underscore` build internal `forOwn` will accept a `thisArg` argument. [closes #220]. Former-commit-id: a7818db29e81b64556232bfe44b2e1275d3dada1 --- build.js | 6 +++--- dist/lodash.js | 4 ++-- dist/lodash.min.js | 2 +- dist/lodash.underscore.js | 6 ++---- dist/lodash.underscore.min.js | 4 ++-- test/test-build.js | 12 ++++++++++++ 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/build.js b/build.js index b49647aad..ba3ece21d 100755 --- a/build.js +++ b/build.js @@ -1865,15 +1865,15 @@ ' var index = -1,', ' length = collection ? collection.length : 0;', '', + " callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg);", " if (typeof length == 'number') {", - " callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg);", ' while (++index < length) {', ' if (callback(collection[index], index, collection) === false) {', ' break;', ' }', ' }', ' } else {', - ' each(collection, callback, thisArg);', + ' each(collection, callback);', ' }', ' return collection;', '}', @@ -2627,7 +2627,7 @@ source = source.replace(matchFunction(source, data.methodName), function(match) { return match .replace(/(callback), *thisArg/g, '$1') - .replace(/^( *)callback *=.+/m, '$1callback || (callback = identity);') + .replace(/^ *callback *=.+\n/m, ''); }); } }); diff --git a/dist/lodash.js b/dist/lodash.js index 4b3d5c71f..dc2488089 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -2346,15 +2346,15 @@ var index = -1, length = collection ? collection.length : 0; + callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg); if (typeof length == 'number') { - callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg); while (++index < length) { if (callback(collection[index], index, collection) === false) { break; } } } else { - forOwn(collection, callback, thisArg); + forOwn(collection, callback); } return collection; } diff --git a/dist/lodash.min.js b/dist/lodash.min.js index cd354fe28..c4ea83438 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -13,7 +13,7 @@ switch(p){case w:case j:return+n==+t;case C:return n!=+n?t!=+t:0==n?1/n==1/t:n== for(;v--;)if(l=p,s=t[v],f)for(;l--&&!(c=L(n[l],s,e,r,u,o)););else if(!(c=L(n[v],s,e,r,u,o)))break;return c}return pe(t,function(t,a,i){return Ut.call(i,a)?(v++,c=Ut.call(n,a)&&L(n[a],t,e,r,u,o)):void 0}),c&&!f&&pe(n,function(n,t,e){return Ut.call(e,t)?c=-1<--v:void 0}),c}function Q(n){return typeof n=="function"}function W(n){return n?I[typeof n]:!1}function X(n){return typeof n=="number"||Jt.call(n)==C}function Y(n){return typeof n=="string"||Jt.call(n)==N}function Z(n,t,e){var r=arguments,u=0,o=2; if(!W(n))return n;if(e===i)var f=r[3],c=r[4],l=r[5];else c=[],l=[],typeof e!="number"&&(o=r.length),3e?Zt(0,u+e):e)||0,typeof u=="number"?a=-1<(Y(n)?n.indexOf(t,e):gt(n,t,e)):se(n,function(n){return++ru&&(u=i)}}else t=!t&&Y(n)?q:a.createCallback(t,e),at(n,function(n,e,a){e=t(n,e,a),e>r&&(r=e,u=n)});return u}function ft(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Ct(r);++earguments.length;t=a.createCallback(t,r,4);var o=-1,i=n.length;if(typeof i=="number")for(u&&(e=n[++o]);++oarguments.length;if(typeof u!="number")var i=oe(n),u=i.length;return t=a.createCallback(t,r,4),at(n,function(r,a,f){a=i?i[--u]:--u,e=o?(o=!1,n[a]):t(e,n[a],a,f)}),e}function pt(n,t,e){var r;t=a.createCallback(t,e),e=-1;var u=n?n.length:0; if(typeof u=="number")for(;++et||typeof n=="undefined")return 1;if(nt||typeof n=="undefined")return 1;if(ne&&(e=r,u=n)});else for(;++ou&&(u=r);return u}function F(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(var u=Array(e);++rarguments.length;r=V(r,u,4);var i=-1,a=n.length;if(typeof a=="number")for(o&&(e=n[++i]);++iarguments.length;if(typeof u!="number")var i=$t(n),u=i.length;return t=V(t,e,4),N(n,function(e,a,f){a=i?i[--u]:--u,r=o?(o=K,n[a]):t(r,n[a],a,f)}),r}function D(n,r,e){var u;r=V(r,e),e=-1;var o=n?n.length:0;if(typeof o=="number")for(;++er?Ft(0,u+r):r||0)-1;else if(r)return e=C(n,t),n[e]===t?e:-1;for(;++e