mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Move bound inheritance hookup inside bound.
Former-commit-id: 7f95fffa14ef42f8f065aad124ac883740baac64
This commit is contained in:
15
lodash.js
15
lodash.js
@@ -587,19 +587,18 @@
|
|||||||
: partialArgs;
|
: partialArgs;
|
||||||
}
|
}
|
||||||
if (this instanceof bound) {
|
if (this instanceof bound) {
|
||||||
|
// ensure `new bound` is an instance of `bound` and `func`
|
||||||
|
noop.prototype = func.prototype;
|
||||||
|
thisBinding = new noop;
|
||||||
|
noop.prototype = null;
|
||||||
|
|
||||||
// mimic the constructor's `return` behavior
|
// mimic the constructor's `return` behavior
|
||||||
// http://es5.github.com/#x13.2.2
|
// http://es5.github.com/#x13.2.2
|
||||||
var result = func.apply(this, args);
|
var result = func.apply(thisBinding, args);
|
||||||
return isObject(result) ? result : this;
|
return isObject(result) ? result : thisBinding;
|
||||||
}
|
}
|
||||||
return func.apply(thisBinding, args);
|
return func.apply(thisBinding, args);
|
||||||
}
|
}
|
||||||
if (func && func.prototype) {
|
|
||||||
// ensure `new bound` is an instance of `bound` and `func`
|
|
||||||
noop.prototype = func.prototype;
|
|
||||||
bound.prototype = new noop;
|
|
||||||
noop.prototype = null;
|
|
||||||
}
|
|
||||||
return bound;
|
return bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,14 +209,6 @@
|
|||||||
bound(['b'], 'c');
|
bound(['b'], 'c');
|
||||||
deepEqual(args, ['a', ['b'], 'c']);
|
deepEqual(args, ['a', ['b'], 'c']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ensure `new bound` is an instance of `bound` and `func`', function() {
|
|
||||||
var func = function() {},
|
|
||||||
bound = _.bind(func, {}),
|
|
||||||
instance = new bound;
|
|
||||||
|
|
||||||
ok(instance instanceof bound && instance instanceof func);
|
|
||||||
});
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user