From 85d8f90bca46a7f1d79f60211198602f6dc86001 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Wed, 24 Feb 2010 13:49:57 -0500 Subject: [PATCH] move the OOP-setup bits down into that section for clarity. JavaScript allows this it's pre-declaration pass. --- underscore.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/underscore.js b/underscore.js index 87034bd2e..87455c6d4 100644 --- a/underscore.js +++ b/underscore.js @@ -45,20 +45,6 @@ nativeIsArray = Array.isArray, nativeKeys = Object.keys; - // If Underscore is called as a function, it returns a wrapped object that - // can be used OO-style. This wrapper holds altered versions of all the - // underscore functions. Wrapped objects may be chained. - var wrapper = function(obj) { this._wrapped = obj; }; - - // A method to easily add functions to the OOP wrapper. - var addToWrapper = function(name, func) { - wrapper.prototype[name] = function() { - var args = _.toArray(arguments); - unshift.call(args, this._wrapped); - return result(func.apply(_, args), this._chain); - }; - }; - // Create a safe reference to the Underscore object for reference below. var _ = function(obj) { return new wrapper(obj); }; @@ -645,11 +631,25 @@ // ------------------------ Setup the OOP Wrapper: -------------------------- + // If Underscore is called as a function, it returns a wrapped object that + // can be used OO-style. This wrapper holds altered versions of all the + // underscore functions. Wrapped objects may be chained. + var wrapper = function(obj) { this._wrapped = obj; }; + // Helper function to continue chaining intermediate results. var result = function(obj, chain) { return chain ? _(obj).chain() : obj; }; + // A method to easily add functions to the OOP wrapper. + var addToWrapper = function(name, func) { + wrapper.prototype[name] = function() { + var args = _.toArray(arguments); + unshift.call(args, this._wrapped); + return result(func.apply(_, args), this._chain); + }; + }; + // Add all of the Underscore functions to the wrapper object. _.mixin(_);