Sha256: 5393f352a794c3fadfb251b81efb11abde3f773b5a78783208a9b8b4d730cf35

Contents?: true

Size: 1.47 KB

Versions: 153

Compression:

Stored size: 1.47 KB

Contents

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() {
    // Use a `switch` statement to work with class constructors.
    // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
    // for more details.
    var args = arguments;
    switch (args.length) {
      case 0: return new Ctor;
      case 1: return new Ctor(args[0]);
      case 2: return new Ctor(args[0], args[1]);
      case 3: return new Ctor(args[0], args[1], args[2]);
      case 4: return new Ctor(args[0], args[1], args[2], args[3]);
      case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
      case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
      case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
    }
    var thisBinding = baseCreate(Ctor.prototype),
        result = Ctor.apply(thisBinding, args);

    // 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;

Version data entries

153 entries across 80 versions & 8 rubygems

Version Path
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/createCtorWrapper.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/inquirer/node_modules/lodash/internal/createCtorWrapper.js