main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var bind = require('function-bind');
|
---|
4 | var GetIntrinsic = require('get-intrinsic');
|
---|
5 | var setFunctionLength = require('set-function-length');
|
---|
6 |
|
---|
7 | var $TypeError = require('es-errors/type');
|
---|
8 | var $apply = GetIntrinsic('%Function.prototype.apply%');
|
---|
9 | var $call = GetIntrinsic('%Function.prototype.call%');
|
---|
10 | var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
|
---|
11 |
|
---|
12 | var $defineProperty = require('es-define-property');
|
---|
13 | var $max = GetIntrinsic('%Math.max%');
|
---|
14 |
|
---|
15 | module.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 | true
|
---|
24 | );
|
---|
25 | };
|
---|
26 |
|
---|
27 | var applyBind = function applyBind() {
|
---|
28 | return $reflectApply(bind, $apply, arguments);
|
---|
29 | };
|
---|
30 |
|
---|
31 | if ($defineProperty) {
|
---|
32 | $defineProperty(module.exports, 'apply', { value: applyBind });
|
---|
33 | } else {
|
---|
34 | module.exports.apply = applyBind;
|
---|
35 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.