massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / function-bind.js
1 'use strict';
2 var global = require('../internals/global');
3 var uncurryThis = require('../internals/function-uncurry-this');
4 var aCallable = require('../internals/a-callable');
5 var isObject = require('../internals/is-object');
6 var hasOwn = require('../internals/has-own-property');
7 var arraySlice = require('../internals/array-slice');
8
9 var Function = global.Function;
10 var concat = uncurryThis([].concat);
11 var join = uncurryThis([].join);
12 var factories = {};
13
14 var construct = function (C, argsLength, args) {
15   if (!hasOwn(factories, argsLength)) {
16     for (var list = [], i = 0; i < argsLength; i++) list[i] = 'a[' + i + ']';
17     factories[argsLength] = Function('C,a', 'return new C(' + join(list, ',') + ')');
18   } return factories[argsLength](C, args);
19 };
20
21 // `Function.prototype.bind` method implementation
22 // https://tc39.es/ecma262/#sec-function.prototype.bind
23 module.exports = Function.bind || function bind(that /* , ...args */) {
24   var F = aCallable(this);
25   var Prototype = F.prototype;
26   var partArgs = arraySlice(arguments, 1);
27   var boundFunction = function bound(/* args... */) {
28     var args = concat(partArgs, arraySlice(arguments));
29     return this instanceof boundFunction ? construct(F, args.length, args) : F.apply(that, args);
30   };
31   if (isObject(Prototype)) boundFunction.prototype = Prototype;
32   return boundFunction;
33 };