From 6d52832a73dcedffd8838ebe0d12fc1d4841588b Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Wed, 28 Oct 2009 12:37:55 -0400 Subject: [PATCH] going to version 0.1.1 with noConflict --- index.html | 16 +++++++++++++--- test/utility.js | 6 ++++++ underscore-min.js | 2 +- underscore.js | 15 +++++++++++++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 9d3ee6e18..db3ee81b0 100644 --- a/index.html +++ b/index.html @@ -102,11 +102,11 @@

- + - +
Development VersionDevelopment Version (0.1.1) 16kb, Uncompressed with Comments
Production VersionProduction Version (0.1.1) 4kb, Packed and Gzipped
@@ -151,7 +151,8 @@

Utility
- uniqueId, template + noConflict, + uniqueId, template

@@ -649,6 +650,15 @@ _.isUndefined(window.missingVariable);

Utility Functions

+ +

+ noConflict_.noConflict() +
+ Give control of the "_" variable back to its previous owner. Returns + a reference to the Underscore object. +

+
+var underscore = _.noConflict();

uniqueId_.uniqueId([prefix]) diff --git a/test/utility.js b/test/utility.js index cfaaaace3..9a8eb516f 100644 --- a/test/utility.js +++ b/test/utility.js @@ -1,6 +1,12 @@ $(document).ready(function() { module("Utility functions (uniqueId, template)"); + + test("utility: noConflict", function() { + var underscore = _.noConflict(); + ok(underscore.isUndefined(_), "The '_' variable has been returned to its previous state."); + window._ = underscore; + }); test("utility: uniqueId", function() { var ids = [], i = 0; diff --git a/underscore-min.js b/underscore-min.js index 6aae0d7e7..096ff0aac 100644 --- a/underscore-min.js +++ b/underscore-min.js @@ -1 +1 @@ -window._={VERSION:"0.1.0",each:function(c,f,a){var g=0;try{if(c.forEach){c.forEach(f,a)}else{if(c.length){for(var d=0;d=a.computed){a={value:g,computed:f}}});return a.value},min:function(d,c,b){if(!c&&_.isArray(d)){return Math.min.apply(Math,d)}var a;_.each(d,function(g,e){var f=c?c.call(b,g,e):g;if(a==null||fd?1:0}),"value")},sortedIndex:function(f,e,c){c=c||function(g){return g};var a=0,d=f.length;while(a>1;c(f[b])=0})})},zip:function(){var a=_.toArray(arguments);var d=_.max(_.pluck(a,"length"));var c=new Array(d);for(var b=0;b)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return b?a(b):a}}; \ No newline at end of file +window.Underscore={VERSION:"0.1.1",PREVIOUS_UNDERSCORE:window._,each:function(c,f,a){var g=0;try{if(c.forEach){c.forEach(f,a)}else{if(c.length){for(var d=0;d=a.computed){a={value:g,computed:f}}});return a.value},min:function(d,c,b){if(!c&&_.isArray(d)){return Math.min.apply(Math,d)}var a;_.each(d,function(g,e){var f=c?c.call(b,g,e):g;if(a==null||fd?1:0}),"value")},sortedIndex:function(f,e,c){c=c||function(g){return g};var a=0,d=f.length;while(a>1;c(f[b])=0})})},zip:function(){var a=_.toArray(arguments);var d=_.max(_.pluck(a,"length"));var c=new Array(d);for(var b=0;b)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return b?a(b):a}};window._=Underscore; \ No newline at end of file diff --git a/underscore.js b/underscore.js index abec6fd9e..0091abd90 100644 --- a/underscore.js +++ b/underscore.js @@ -5,9 +5,11 @@ // Oliver Steele's Functional, And John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore/ -window._ = { +window.Underscore = { - VERSION : '0.1.0', + VERSION : '0.1.1', + + PREVIOUS_UNDERSCORE : window._, /*------------------------ Collection Functions: ---------------------------*/ @@ -387,6 +389,13 @@ window._ = { /* -------------------------- Utility Functions: -------------------------- */ + // Run Underscore.js in noConflict mode, returning the '_' variable to its + // previous owner. Returns a reference to the Underscore object. + noConflict : function() { + window._ = Underscore.PREVIOUS_UNDERSCORE; + return this; + }, + // Generate a unique integer id (unique within the entire client session). // Useful for temporary DOM ids. uniqueId : function(prefix) { @@ -413,3 +422,5 @@ window._ = { } }; + +window._ = Underscore;