mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
24 lines
738 B
JavaScript
24 lines
738 B
JavaScript
![]() |
var baseCreate = require('./baseCreate'),
|
||
|
isObject = require('../lang/isObject');
|
||
|
|
||
|
/**
|
||
|
* Creates a function that produces an instance of `Ctor` regardless of
|
||
|
* whether it was invoked as part of a `new` expression or by `call` or `apply`.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {Function} Ctor The constructor to wrap.
|
||
|
* @returns {Function} Returns the new wrapped function.
|
||
|
*/
|
||
|
function createCtorWrapper(Ctor) {
|
||
|
return function() {
|
||
|
var thisBinding = baseCreate(Ctor.prototype),
|
||
|
result = Ctor.apply(thisBinding, arguments);
|
||
|
|
||
|
// Mimic the constructor's `return` behavior.
|
||
|
// See https://es5.github.io/#x13.2.2 for more details.
|
||
|
return isObject(result) ? result : thisBinding;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
module.exports = createCtorWrapper;
|