|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
977 bytes
|
| Line | |
|---|
| 1 | import restArguments from './restArguments.js';
|
|---|
| 2 | import executeBound from './_executeBound.js';
|
|---|
| 3 | import _ from './underscore.js';
|
|---|
| 4 |
|
|---|
| 5 | // Partially apply a function by creating a version that has had some of its
|
|---|
| 6 | // arguments pre-filled, without changing its dynamic `this` context. `_` acts
|
|---|
| 7 | // as a placeholder by default, allowing any combination of arguments to be
|
|---|
| 8 | // pre-filled. Set `_.partial.placeholder` for a custom placeholder argument.
|
|---|
| 9 | var partial = restArguments(function(func, boundArgs) {
|
|---|
| 10 | var placeholder = partial.placeholder;
|
|---|
| 11 | var bound = function() {
|
|---|
| 12 | var position = 0, length = boundArgs.length;
|
|---|
| 13 | var args = Array(length);
|
|---|
| 14 | for (var i = 0; i < length; i++) {
|
|---|
| 15 | args[i] = boundArgs[i] === placeholder ? arguments[position++] : boundArgs[i];
|
|---|
| 16 | }
|
|---|
| 17 | while (position < arguments.length) args.push(arguments[position++]);
|
|---|
| 18 | return executeBound(func, bound, this, this, args);
|
|---|
| 19 | };
|
|---|
| 20 | return bound;
|
|---|
| 21 | });
|
|---|
| 22 |
|
|---|
| 23 | partial.placeholder = _;
|
|---|
| 24 | export default partial;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.