Rework lodash.

This commit is contained in:
John-David Dalton
2014-06-20 00:14:05 -07:00
parent 7d63970293
commit 3a25ecbbc9

View File

@@ -791,10 +791,13 @@
* // => true * // => true
*/ */
function lodash(value) { function lodash(value) {
// don't wrap if already wrapped, even if wrapped by a different `lodash` constructor if (value instanceof lodashWrapper) {
return (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__')) return value;
? value }
: new lodashWrapper(value); if (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__')) {
value = value.__wrapped__;
}
return new lodashWrapper(value);
} }
/** /**
@@ -809,8 +812,6 @@
this.__chain__ = !!chainAll; this.__chain__ = !!chainAll;
this.__wrapped__ = value; this.__wrapped__ = value;
} }
// ensure `new lodashWrapper` is an instance of `lodash`
lodashWrapper.prototype = lodash.prototype;
/** /**
* An object used to flag environments features. * An object used to flag environments features.
@@ -8605,6 +8606,9 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
// ensure `new lodashWrapper` is an instance of `lodash`
lodashWrapper.prototype = lodash.prototype;
// add functions that return wrapped values when chaining // add functions that return wrapped values when chaining
lodash.after = after; lodash.after = after;
lodash.assign = assign; lodash.assign = assign;