From b5e1101610ac5a957e685acf9494e0d297b41d5f Mon Sep 17 00:00:00 2001
From: Jeremy Ashkenas
@@ -803,7 +803,9 @@ moe === _.identity(moe);
breakLoop
-
Development Version (0.4.2)
+ Development Version (0.4.3)
18kb, Uncompressed with Comments
-
Production Version (0.4.2)
+ Production Version (0.4.3)
2kb, Packed and Gzipped
_.breakLoop()
Breaks out of the current loop iteration. Similar to the break
- 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 StopIteration object in JavaScript 1.7 compliant
+ browsers.
var result = null;
@@ -889,6 +891,12 @@ _([1, 2, 3]).value();
Change Log
+
+ 0.4.3
+ Started using the native StopIteration object in browsers that support it.
+ Fixed Underscore setup for CommonJS environments.
+
+
0.4.2
Renamed the unwrapping function to value, for clarity.
diff --git a/underscore-min.js b/underscore-min.js
index 20e7c78b1..0e6235f5d 100644
--- a/underscore-min.js
+++ b/underscore-min.js
@@ -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.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;nk?1:0}),"value")};d.sortedIndex=function(n,m,j){j=j||d.identity;var g=0,k=n.length;while(g>1;j(n[h])=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=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}})();
\ No newline at end of file
+(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.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;om?1:0}),"value")};d.sortedIndex=function(o,n,k){k=k||d.identity;var h=0,m=o.length;while(h>1;k(o[j])=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=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}})();
\ No newline at end of file
diff --git a/underscore.js b/underscore.js
index 039bb04c9..99e738419 100644
--- a/underscore.js
+++ b/underscore.js
@@ -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).