|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
933 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | function bindKey(object, key, ...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 === bindKey.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 object[key](...args);
|
|---|
| 23 | }
|
|---|
| 24 | return object[key].apply(object, args);
|
|---|
| 25 | };
|
|---|
| 26 | return bound;
|
|---|
| 27 | }
|
|---|
| 28 | const bindKeyPlaceholder = Symbol('bindKey.placeholder');
|
|---|
| 29 | bindKey.placeholder = bindKeyPlaceholder;
|
|---|
| 30 |
|
|---|
| 31 | exports.bindKey = bindKey;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.