CoolFace
Apppublic

Umama-at-Bluchip/Quick-UI

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
index.js36 linesDownload Raw Back to call-bind
1'use strict';2 3var bind = require('function-bind');4var GetIntrinsic = require('get-intrinsic');5var setFunctionLength = require('set-function-length');6 7var $TypeError = require('es-errors/type');8var $apply = GetIntrinsic('%Function.prototype.apply%');9var $call = GetIntrinsic('%Function.prototype.call%');10var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);11 12var $defineProperty = require('es-define-property');13var $max = GetIntrinsic('%Math.max%');14 15module.exports = function callBind(originalFunction) {16	if (typeof originalFunction !== 'function') {17		throw new $TypeError('a function is required');18	}19	var func = $reflectApply(bind, $call, arguments);20	return setFunctionLength(21		func,22		1 + $max(0, originalFunction.length - (arguments.length - 1)),23		true24	);25};26 27var applyBind = function applyBind() {28	return $reflectApply(bind, $apply, arguments);29};30 31if ($defineProperty) {32	$defineProperty(module.exports, 'apply', { value: applyBind });33} else {34	module.exports.apply = applyBind;35}36