[79a0317] | 1 | 'use strict';
|
---|
| 2 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
| 3 | var aCallable = require('../internals/a-callable');
|
---|
| 4 | var isObject = require('../internals/is-object');
|
---|
| 5 | var hasOwn = require('../internals/has-own-property');
|
---|
| 6 | var arraySlice = require('../internals/array-slice');
|
---|
| 7 | var NATIVE_BIND = require('../internals/function-bind-native');
|
---|
| 8 |
|
---|
| 9 | var $Function = 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 | var list = [];
|
---|
| 17 | var i = 0;
|
---|
| 18 | for (; i < argsLength; i++) list[i] = 'a[' + i + ']';
|
---|
| 19 | factories[argsLength] = $Function('C,a', 'return new C(' + join(list, ',') + ')');
|
---|
| 20 | } return factories[argsLength](C, args);
|
---|
| 21 | };
|
---|
| 22 |
|
---|
| 23 | // `Function.prototype.bind` method implementation
|
---|
| 24 | // https://tc39.es/ecma262/#sec-function.prototype.bind
|
---|
| 25 | // eslint-disable-next-line es/no-function-prototype-bind -- detection
|
---|
| 26 | module.exports = NATIVE_BIND ? $Function.bind : function bind(that /* , ...args */) {
|
---|
| 27 | var F = aCallable(this);
|
---|
| 28 | var Prototype = F.prototype;
|
---|
| 29 | var partArgs = arraySlice(arguments, 1);
|
---|
| 30 | var boundFunction = function bound(/* args... */) {
|
---|
| 31 | var args = concat(partArgs, arraySlice(arguments));
|
---|
| 32 | return this instanceof boundFunction ? construct(F, args.length, args) : F.apply(that, args);
|
---|
| 33 | };
|
---|
| 34 | if (isObject(Prototype)) boundFunction.prototype = Prototype;
|
---|
| 35 | return boundFunction;
|
---|
| 36 | };
|
---|