From f591f685466bc04d52b932b021e8d72b7225a6ea Mon Sep 17 00:00:00 2001 From: Mike Frawley Date: Tue, 23 Feb 2010 18:04:47 -0600 Subject: [PATCH] make _.initWrapper() that builds the wrapper prototye The intention is that underscore Consumers MUST call _.initWrapper() in their code to allow the OO style usage, or a runtime error is thrown. This would break backwards compatability, so for the moment I call initWrapper myself at the end of underscore. However, if I comment out my call to initWrapper and don't call it in user code, then the compiler can strip an empty underscore with no user code from 2137 -> 100 bytes. Making the user explicitly say they want OO wrapping is the only way to achieve this, otherwise the compiler will always keep the OO wrapper code around. --- underscore.js | 102 +++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 46 deletions(-) diff --git a/underscore.js b/underscore.js index 7e8b24865..53d70c503 100644 --- a/underscore.js +++ b/underscore.js @@ -43,7 +43,7 @@ native_keys = Object['keys']; // Create a safe reference to the Underscore object for reference below. - var _ = function(obj) { return new wrapper(obj); }; + var _ = function(obj) { return _.buildWrapper(obj) }; // Export the Underscore object for CommonJS. if (typeof exports !== 'undefined') exports._ = _; @@ -68,8 +68,11 @@ } else if (_.isNumber(obj.length)) { for (var i=0, l=obj.length; i