.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / function-bind.js
1 'use strict';
2 var aFunction = require('../internals/a-function');
3 var isObject = require('../internals/is-object');
4
5 var slice = [].slice;
6 var factories = {};
7
8 var construct = function (C, argsLength, args) {
9   if (!(argsLength in factories)) {
10     for (var list = [], i = 0; i < argsLength; i++) list[i] = 'a[' + i + ']';
11     // eslint-disable-next-line no-new-func -- we have no proper alternatives, IE8- only
12     factories[argsLength] = Function('C,a', 'return new C(' + list.join(',') + ')');
13   } return factories[argsLength](C, args);
14 };
15
16 // `Function.prototype.bind` method implementation
17 // https://tc39.es/ecma262/#sec-function.prototype.bind
18 module.exports = Function.bind || function bind(that /* , ...args */) {
19   var fn = aFunction(this);
20   var partArgs = slice.call(arguments, 1);
21   var boundFunction = function bound(/* args... */) {
22     var args = partArgs.concat(slice.call(arguments));
23     return this instanceof boundFunction ? construct(fn, args.length, args) : fn.apply(that, args);
24   };
25   if (isObject(fn.prototype)) boundFunction.prototype = fn.prototype;
26   return boundFunction;
27 };