source: node_modules/es-toolkit/dist/compat/function/bind.js@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 898 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5function bind(func, thisObj, ...partialArgs) {
6 const bound = function (...providedArgs) {
7 const args = [];
8 let startIndex = 0;
9 for (let i = 0; i < partialArgs.length; i++) {
10 const arg = partialArgs[i];
11 if (arg === bind.placeholder) {
12 args.push(providedArgs[startIndex++]);
13 }
14 else {
15 args.push(arg);
16 }
17 }
18 for (let i = startIndex; i < providedArgs.length; i++) {
19 args.push(providedArgs[i]);
20 }
21 if (this instanceof bound) {
22 return new func(...args);
23 }
24 return func.apply(thisObj, args);
25 };
26 return bound;
27}
28const bindPlaceholder = Symbol('bind.placeholder');
29bind.placeholder = bindPlaceholder;
30
31exports.bind = bind;
Note: See TracBrowser for help on using the repository browser.