3 var bind = require('function-bind');
4 var GetIntrinsic = require('get-intrinsic');
6 var $apply = GetIntrinsic('%Function.prototype.apply%');
7 var $call = GetIntrinsic('%Function.prototype.call%');
8 var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
10 var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true);
11 var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
12 var $max = GetIntrinsic('%Math.max%');
14 if ($defineProperty) {
16 $defineProperty({}, 'a', { value: 1 });
18 // IE 8 has a broken defineProperty
19 $defineProperty = null;
23 module.exports = function callBind(originalFunction) {
24 var func = $reflectApply(bind, $call, arguments);
25 if ($gOPD && $defineProperty) {
26 var desc = $gOPD(func, 'length');
27 if (desc.configurable) {
28 // original length, plus the receiver, minus any additional arguments (after the receiver)
32 { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) }
39 var applyBind = function applyBind() {
40 return $reflectApply(bind, $apply, arguments);
43 if ($defineProperty) {
44 $defineProperty(module.exports, 'apply', { value: applyBind });
46 module.exports.apply = applyBind;