1
0
Fork 0
forked from svrjs/svrjs
This repository has been archived on 2024-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs/node_modules/call-bind/index.js

36 lines
1 KiB
JavaScript
Raw Permalink Normal View History

2023-07-29 20:33:28 +02:00
'use strict';
var bind = require('function-bind');
var GetIntrinsic = require('get-intrinsic');
2024-08-26 08:36:01 +02:00
var setFunctionLength = require('set-function-length');
2023-07-29 20:33:28 +02:00
2024-08-26 08:36:01 +02:00
var $TypeError = require('es-errors/type');
2023-07-29 20:33:28 +02:00
var $apply = GetIntrinsic('%Function.prototype.apply%');
var $call = GetIntrinsic('%Function.prototype.call%');
var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
2024-08-26 08:36:01 +02:00
var $defineProperty = require('es-define-property');
2023-07-29 20:33:28 +02:00
var $max = GetIntrinsic('%Math.max%');
module.exports = function callBind(originalFunction) {
2024-08-26 08:36:01 +02:00
if (typeof originalFunction !== 'function') {
throw new $TypeError('a function is required');
2023-07-29 20:33:28 +02:00
}
2024-08-26 08:36:01 +02:00
var func = $reflectApply(bind, $call, arguments);
return setFunctionLength(
func,
1 + $max(0, originalFunction.length - (arguments.length - 1)),
true
);
2023-07-29 20:33:28 +02:00
};
var applyBind = function applyBind() {
return $reflectApply(bind, $apply, arguments);
};
if ($defineProperty) {
$defineProperty(module.exports, 'apply', { value: applyBind });
} else {
module.exports.apply = applyBind;
}