Permalink
Browse files

0.4.3, with fixed export for CommonJS and StopIteration support

  • Loading branch information...
1 parent 111f1cb commit b5e1101610ac5a957e685acf9494e0d297b41d5f @jashkenas jashkenas committed Nov 10, 2009
Showing with 19 additions and 13 deletions.
  1. +11 −3 index.html
  2. +1 −1 underscore-min.js
  3. +7 −9 underscore.js
View
@@ -107,11 +107,11 @@
<p>
<table>
<tr>
- <td><a href="underscore.js">Development Version (0.4.2)</a></td>
+ <td><a href="underscore.js">Development Version (0.4.3)</a></td>
<td><i>18kb, Uncompressed with Comments</i></td>
</tr>
<tr>
- <td><a href="underscore-min.js">Production Version (0.4.2)</a></td>
+ <td><a href="underscore-min.js">Production Version (0.4.3)</a></td>
<td><i>2kb, Packed and Gzipped</i></td>
</tr>
</table>
@@ -803,7 +803,9 @@ <h2 id="styles">Object-Oriented and Functional Styles</h2>
<b class="header">breakLoop</b><code>_.breakLoop()</code>
<br />
Breaks out of the current loop iteration. Similar to the <tt>break</tt>
- keyword in regular "for" loop, but works within an iterator function.
+ keyword in regular "for" loop, but works within an iterator function.
+ Uses the native <tt>StopIteration</tt> object in JavaScript 1.7 compliant
+ browsers.
</p>
<pre>
var result = null;
@@ -890,6 +892,12 @@ <h2 id="styles">Object-Oriented and Functional Styles</h2>
<h2>Change Log</h2>
<p>
+ <b class="header">0.4.3</b><br />
+ Started using the native StopIteration object in browsers that support it.
+ Fixed Underscore setup for CommonJS environments.
+ </p>
+
+ <p>
<b class="header">0.4.2</b><br />
Renamed the unwrapping function to <tt>value</tt>, for clarity.
</p>
View
@@ -1 +1 @@
-(function(){var c=this;var e=c._;var f=function(g){this._wrapped=g};var d=c._=function(g){return new f(g)};if(module&&typeof module.exports!=='undefined'){module.exports=d}else{if(typeof exports!=='undefined'){d=exports}}d.VERSION="0.4.2";d.each=function(p,n,m){var h=0;try{if(p.forEach){p.forEach(n,m)}else{if(p.length){for(var k=0,g=p.length;k<g;k++){n.call(m,p[k],k,p)}}else{for(var j in p){if(Object.prototype.hasOwnProperty.call(p,j)){n.call(m,p[j],j,p)}}}}}catch(o){if(o!="__break__"){throw o}}return p};d.map=function(k,j,h){if(k&&k.map){return k.map(j,h)}var g=[];d.each(k,function(o,m,n){g.push(j.call(h,o,m,n))});return g};d.reduce=function(k,g,j,h){if(k&&k.reduce){return k.reduce(d.bind(j,h),g)}d.each(k,function(o,m,n){g=j.call(h,g,o,m,n)});return g};d.reduceRight=function(k,g,j,h){if(k&&k.reduceRight){return k.reduceRight(d.bind(j,h),g)}var m=d.clone(d.toArray(k)).reverse();d.each(m,function(o,n){g=j.call(h,g,o,n,k)});return g};d.detect=function(k,j,h){var g;d.each(k,function(o,m,n){if(j.call(h,o,m,n)){g=o;d.breakLoop()}});return g};d.select=function(k,j,h){if(k.filter){return k.filter(j,h)}var g=[];d.each(k,function(o,m,n){j.call(h,o,m,n)&&g.push(o)});return g};d.reject=function(k,j,h){var g=[];d.each(k,function(o,m,n){!j.call(h,o,m,n)&&g.push(o)});return g};d.all=function(k,j,h){j=j||d.identity;if(k.every){return k.every(j,h)}var g=true;d.each(k,function(o,m,n){if(!(g=g&&j.call(h,o,m,n))){d.breakLoop()}});return g};d.any=function(k,j,h){j=j||d.identity;if(k.some){return k.some(j,h)}var g=false;d.each(k,function(o,m,n){if(g=j.call(h,o,m,n)){d.breakLoop()}});return g};d.include=function(j,h){if(d.isArray(j)){return d.indexOf(j,h)!=-1}var g=false;d.each(j,function(k){if(g=k===h){d.breakLoop()}});return g};d.invoke=function(h,j){var g=d.toArray(arguments).slice(2);return d.map(h,function(k){return(j?k[j]:k).apply(k,g)})};d.pluck=function(h,g){return d.map(h,function(j){return j[g]})};d.max=function(k,j,h){if(!j&&d.isArray(k)){return Math.max.apply(Math,k)}var g={computed:-Infinity};d.each(k,function(p,m,o){var n=j?j.call(h,p,m,o):p;n>=g.computed&&(g={value:p,computed:n})});return g.value};d.min=function(k,j,h){if(!j&&d.isArray(k)){return Math.min.apply(Math,k)}var g={computed:Infinity};d.each(k,function(p,m,o){var n=j?j.call(h,p,m,o):p;n<g.computed&&(g={value:p,computed:n})});return g.value};d.sortBy=function(j,h,g){return d.pluck(d.map(j,function(n,k,m){return{value:n,criteria:h.call(g,n,k,m)}}).sort(function(o,n){var m=o.criteria,k=n.criteria;return m<k?-1:m>k?1:0}),"value")};d.sortedIndex=function(n,m,j){j=j||d.identity;var g=0,k=n.length;while(g<k){var h=(g+k)>>1;j(n[h])<j(m)?g=h+1:k=h}return g};d.toArray=function(g){if(!g){return[]}if(d.isArray(g)){return g}return d.map(g,function(h){return h})};d.size=function(g){return d.toArray(g).length};d.first=function(g){return g[0]};d.last=function(g){return g[g.length-1]};d.compact=function(g){return d.select(g,function(h){return !!h})};d.flatten=function(g){return d.reduce(g,[],function(h,j){if(d.isArray(j)){return h.concat(d.flatten(j))}h.push(j);return h})};d.without=function(h){var g=h.slice.call(arguments,0);return d.select(h,function(j){return !d.include(g,j)})};d.uniq=function(h,g){return d.reduce(h,[],function(j,m,k){if(0==k||(g?d.last(j)!=m:!d.include(j,m))){j.push(m)}return j})};d.intersect=function(h){var g=d.toArray(arguments).slice(1);return d.select(d.uniq(h),function(j){return d.all(g,function(k){return d.indexOf(k,j)>=0})})};d.zip=function(){var g=d.toArray(arguments);var k=d.max(d.pluck(g,"length"));var j=new Array(k);for(var h=0;h<k;h++){j[h]=d.pluck(g,String(h))}return j};d.indexOf=function(h,g){if(h.indexOf){return h.indexOf(g)}for(i=0,l=h.length;i<l;i++){if(h[i]===g){return i}}return -1};d.lastIndexOf=function(j,h){if(j.lastIndexOf){return j.lastIndexOf(h)}var g=j.length;while(g--){if(j[g]===h){return g}}return -1};d.bind=function(j,h){h=h||c;var g=d.toArray(arguments).slice(2);return function(){var k=g.concat(d.toArray(arguments));return j.apply(h,k)}};d.bindAll=function(){var g=d.toArray(arguments);var h=g.pop();d.each(g,function(j){h[j]=d.bind(h[j],h)})};d.delay=function(h,j){var g=d.toArray(arguments).slice(2);return setTimeout(function(){return h.apply(h,g)},j)};d.defer=function(g){return d.delay.apply(d,[g,1].concat(d.toArray(arguments).slice(1)))};d.wrap=function(g,h){return function(){var j=[g].concat(d.toArray(arguments));return h.apply(h,j)}};d.compose=function(){var g=d.toArray(arguments);return function(){for(var h=g.length-1;h>=0;h--){arguments=[g[h].apply(this,arguments)]}return arguments[0]}};d.keys=function(g){return d.map(g,function(j,h){return h})};d.values=function(g){return d.map(g,d.identity)};d.extend=function(g,j){for(var h in j){g[h]=j[h]}return g};d.clone=function(g){if(d.isArray(g)){return g.slice(0)}return d.extend({},g)};d.isEqual=function(h,g){if(h===g){return true}var m=typeof(h),o=typeof(g);if(m!=o){return false}if(h==g){return true}if(h.isEqual){return h.isEqual(g)}if(m!=="object"){return false}var j=d.keys(h),n=d.keys(g);if(j.length!=n.length){return false}for(var k in h){if(!d.isEqual(h[k],g[k])){return false}}return true};d.isEmpty=function(g){return(d.isArray(g)?g:d.values(g)).length==0};d.isElement=function(g){return !!(g&&g.nodeType==1)};d.isArray=function(g){return Object.prototype.toString.call(g)=="[object Array]"};d.isFunction=function(g){return Object.prototype.toString.call(g)=="[object Function]"};d.isUndefined=function(g){return typeof g=="undefined"};d.noConflict=function(){c._=e;return this};d.identity=function(g){return g};d.breakLoop=function(){throw"__break__"};var b=0;d.uniqueId=function(g){var h=b++;return g?g+h:h};d.functions=function(){var h=[];for(var g in d){if(Object.prototype.hasOwnProperty.call(d,g)){h.push(g)}}return d.without(h,"VERSION","prototype","noConflict").sort()};d.template=function(j,h){var g=new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+j.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 h?g(h):g};d.forEach=d.each;d.foldl=d.inject=d.reduce;d.foldr=d.reduceRight;d.filter=d.select;d.every=d.all;d.some=d.any;d.methods=d.functions;var a=function(h,g){return g?d(h).chain():h};d.each(d.functions(),function(g){f.prototype[g]=function(){Array.prototype.unshift.call(arguments,this._wrapped);return a(d[g].apply(d,arguments),this._chain)}});d.each(["pop","push","reverse","shift","sort","splice","unshift"],function(g){f.prototype[g]=function(){Array.prototype[g].apply(this._wrapped,arguments);return a(this._wrapped,this._chain)}});d.each(["concat","join","slice"],function(g){f.prototype[g]=function(){return a(Array.prototype[g].apply(this._wrapped,arguments),this._chain)}});f.prototype.chain=function(){this._chain=true;return this};f.prototype.value=function(){return this._wrapped}})();
+(function(){var c=this;var e=c._;var g=function(h){this._wrapped=h};var f=typeof StopIteration!=="undefined"?StopIteration:"__break__";var d=c._=function(h){return new g(h)};if(typeof exports!=="undefined"){exports._=d}d.VERSION="0.4.3";d.each=function(q,o,n){var j=0;try{if(q.forEach){q.forEach(o,n)}else{if(q.length){for(var m=0,h=q.length;m<h;m++){o.call(n,q[m],m,q)}}else{for(var k in q){if(Object.prototype.hasOwnProperty.call(q,k)){o.call(n,q[k],k,q)}}}}}catch(p){if(p!=f){throw p}}return q};d.map=function(m,k,j){if(m&&m.map){return m.map(k,j)}var h=[];d.each(m,function(p,n,o){h.push(k.call(j,p,n,o))});return h};d.reduce=function(m,h,k,j){if(m&&m.reduce){return m.reduce(d.bind(k,j),h)}d.each(m,function(p,n,o){h=k.call(j,h,p,n,o)});return h};d.reduceRight=function(m,h,k,j){if(m&&m.reduceRight){return m.reduceRight(d.bind(k,j),h)}var n=d.clone(d.toArray(m)).reverse();d.each(n,function(p,o){h=k.call(j,h,p,o,m)});return h};d.detect=function(m,k,j){var h;d.each(m,function(p,n,o){if(k.call(j,p,n,o)){h=p;d.breakLoop()}});return h};d.select=function(m,k,j){if(m.filter){return m.filter(k,j)}var h=[];d.each(m,function(p,n,o){k.call(j,p,n,o)&&h.push(p)});return h};d.reject=function(m,k,j){var h=[];d.each(m,function(p,n,o){!k.call(j,p,n,o)&&h.push(p)});return h};d.all=function(m,k,j){k=k||d.identity;if(m.every){return m.every(k,j)}var h=true;d.each(m,function(p,n,o){if(!(h=h&&k.call(j,p,n,o))){d.breakLoop()}});return h};d.any=function(m,k,j){k=k||d.identity;if(m.some){return m.some(k,j)}var h=false;d.each(m,function(p,n,o){if(h=k.call(j,p,n,o)){d.breakLoop()}});return h};d.include=function(k,j){if(d.isArray(k)){return d.indexOf(k,j)!=-1}var h=false;d.each(k,function(m){if(h=m===j){d.breakLoop()}});return h};d.invoke=function(j,k){var h=d.toArray(arguments).slice(2);return d.map(j,function(m){return(k?m[k]:m).apply(m,h)})};d.pluck=function(j,h){return d.map(j,function(k){return k[h]})};d.max=function(m,k,j){if(!k&&d.isArray(m)){return Math.max.apply(Math,m)}var h={computed:-Infinity};d.each(m,function(q,n,p){var o=k?k.call(j,q,n,p):q;o>=h.computed&&(h={value:q,computed:o})});return h.value};d.min=function(m,k,j){if(!k&&d.isArray(m)){return Math.min.apply(Math,m)}var h={computed:Infinity};d.each(m,function(q,n,p){var o=k?k.call(j,q,n,p):q;o<h.computed&&(h={value:q,computed:o})});return h.value};d.sortBy=function(k,j,h){return d.pluck(d.map(k,function(o,m,n){return{value:o,criteria:j.call(h,o,m,n)}}).sort(function(p,o){var n=p.criteria,m=o.criteria;return n<m?-1:n>m?1:0}),"value")};d.sortedIndex=function(o,n,k){k=k||d.identity;var h=0,m=o.length;while(h<m){var j=(h+m)>>1;k(o[j])<k(n)?h=j+1:m=j}return h};d.toArray=function(h){if(!h){return[]}if(d.isArray(h)){return h}return d.map(h,function(j){return j})};d.size=function(h){return d.toArray(h).length};d.first=function(h){return h[0]};d.last=function(h){return h[h.length-1]};d.compact=function(h){return d.select(h,function(j){return !!j})};d.flatten=function(h){return d.reduce(h,[],function(j,k){if(d.isArray(k)){return j.concat(d.flatten(k))}j.push(k);return j})};d.without=function(j){var h=j.slice.call(arguments,0);return d.select(j,function(k){return !d.include(h,k)})};d.uniq=function(j,h){return d.reduce(j,[],function(k,n,m){if(0==m||(h?d.last(k)!=n:!d.include(k,n))){k.push(n)}return k})};d.intersect=function(j){var h=d.toArray(arguments).slice(1);return d.select(d.uniq(j),function(k){return d.all(h,function(m){return d.indexOf(m,k)>=0})})};d.zip=function(){var h=d.toArray(arguments);var m=d.max(d.pluck(h,"length"));var k=new Array(m);for(var j=0;j<m;j++){k[j]=d.pluck(h,String(j))}return k};d.indexOf=function(j,h){if(j.indexOf){return j.indexOf(h)}for(i=0,l=j.length;i<l;i++){if(j[i]===h){return i}}return -1};d.lastIndexOf=function(k,j){if(k.lastIndexOf){return k.lastIndexOf(j)}var h=k.length;while(h--){if(k[h]===j){return h}}return -1};d.bind=function(k,j){j=j||c;var h=d.toArray(arguments).slice(2);return function(){var m=h.concat(d.toArray(arguments));return k.apply(j,m)}};d.bindAll=function(){var h=d.toArray(arguments);var j=h.pop();d.each(h,function(k){j[k]=d.bind(j[k],j)})};d.delay=function(j,k){var h=d.toArray(arguments).slice(2);return setTimeout(function(){return j.apply(j,h)},k)};d.defer=function(h){return d.delay.apply(d,[h,1].concat(d.toArray(arguments).slice(1)))};d.wrap=function(h,j){return function(){var k=[h].concat(d.toArray(arguments));return j.apply(j,k)}};d.compose=function(){var h=d.toArray(arguments);return function(){for(var j=h.length-1;j>=0;j--){arguments=[h[j].apply(this,arguments)]}return arguments[0]}};d.keys=function(h){return d.map(h,function(k,j){return j})};d.values=function(h){return d.map(h,d.identity)};d.extend=function(h,k){for(var j in k){h[j]=k[j]}return h};d.clone=function(h){if(d.isArray(h)){return h.slice(0)}return d.extend({},h)};d.isEqual=function(j,h){if(j===h){return true}var n=typeof(j),p=typeof(h);if(n!=p){return false}if(j==h){return true}if(j.isEqual){return j.isEqual(h)}if(n!=="object"){return false}var k=d.keys(j),o=d.keys(h);if(k.length!=o.length){return false}for(var m in j){if(!d.isEqual(j[m],h[m])){return false}}return true};d.isEmpty=function(h){return(d.isArray(h)?h:d.values(h)).length==0};d.isElement=function(h){return !!(h&&h.nodeType==1)};d.isArray=function(h){return Object.prototype.toString.call(h)=="[object Array]"};d.isFunction=function(h){return Object.prototype.toString.call(h)=="[object Function]"};d.isUndefined=function(h){return typeof h=="undefined"};d.noConflict=function(){c._=e;return this};d.identity=function(h){return h};d.breakLoop=function(){throw f};var b=0;d.uniqueId=function(h){var j=b++;return h?h+j:j};d.functions=function(){var j=[];for(var h in d){if(Object.prototype.hasOwnProperty.call(d,h)){j.push(h)}}return d.without(j,"VERSION","prototype","noConflict").sort()};d.template=function(k,j){var h=new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+k.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 j?h(j):h};d.forEach=d.each;d.foldl=d.inject=d.reduce;d.foldr=d.reduceRight;d.filter=d.select;d.every=d.all;d.some=d.any;d.methods=d.functions;var a=function(j,h){return h?d(j).chain():j};d.each(d.functions(),function(h){g.prototype[h]=function(){Array.prototype.unshift.call(arguments,this._wrapped);return a(d[h].apply(d,arguments),this._chain)}});d.each(["pop","push","reverse","shift","sort","splice","unshift"],function(h){g.prototype[h]=function(){Array.prototype[h].apply(this._wrapped,arguments);return a(this._wrapped,this._chain)}});d.each(["concat","join","slice"],function(h){g.prototype[h]=function(){return a(Array.prototype[h].apply(this._wrapped,arguments),this._chain)}});g.prototype.chain=function(){this._chain=true;return this};g.prototype.value=function(){return this._wrapped}})();
View
@@ -21,19 +21,17 @@
// underscore functions. Wrapped objects may be chained.
var wrapper = function(obj) { this._wrapped = obj; };
+ // Establish the object that gets thrown to break out of a loop iteration.
+ var breaker = typeof StopIteration !== 'undefined' ? StopIteration : '__break__';
+
// Create a safe reference to the Underscore object for reference below.
var _ = root._ = function(obj) { return new wrapper(obj); };
// Export the Underscore object for CommonJS.
- if (module && typeof module.exports !== 'undefined') {
- // richer binding for systems that allow it (node.js for example)
- module.exports = _;
- } else {
- if (typeof exports !== 'undefined') _ = exports;
- }
+ if (typeof exports !== 'undefined') exports._ = _;
// Current version.
- _.VERSION = '0.4.2';
+ _.VERSION = '0.4.3';
/*------------------------ Collection Functions: ---------------------------*/
@@ -52,7 +50,7 @@
}
}
} catch(e) {
- if (e != '__break__') throw e;
+ if (e != breaker) throw e;
}
return obj;
};
@@ -453,7 +451,7 @@
// Break out of the middle of an iteration.
_.breakLoop = function() {
- throw "__break__";
+ throw breaker;
};
// Generate a unique integer id (unique within the entire client session).

0 comments on commit b5e1101

Please sign in to comment.