1 var baseCreate = require('./baseCreate'),
2 isObject = require('../lang/isObject');
5 * Creates a function that produces an instance of `Ctor` regardless of
6 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
9 * @param {Function} Ctor The constructor to wrap.
10 * @returns {Function} Returns the new wrapped function.
12 function createCtorWrapper(Ctor) {
14 var thisBinding = baseCreate(Ctor.prototype),
15 result = Ctor.apply(thisBinding, arguments);
17 // Mimic the constructor's `return` behavior.
18 // See https://es5.github.io/#x13.2.2 for more details.
19 return isObject(result) ? result : thisBinding;
23 module.exports = createCtorWrapper;