main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
564 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * Syntactic sugar for invoking a function and expanding an array for arguments.
|
---|
5 | *
|
---|
6 | * Common use case would be to use `Function.prototype.apply`.
|
---|
7 | *
|
---|
8 | * ```js
|
---|
9 | * function f(x, y, z) {}
|
---|
10 | * var args = [1, 2, 3];
|
---|
11 | * f.apply(null, args);
|
---|
12 | * ```
|
---|
13 | *
|
---|
14 | * With `spread` this example can be re-written.
|
---|
15 | *
|
---|
16 | * ```js
|
---|
17 | * spread(function(x, y, z) {})([1, 2, 3]);
|
---|
18 | * ```
|
---|
19 | *
|
---|
20 | * @param {Function} callback
|
---|
21 | *
|
---|
22 | * @returns {Function}
|
---|
23 | */
|
---|
24 | export default function spread(callback) {
|
---|
25 | return function wrap(arr) {
|
---|
26 | return callback.apply(null, arr);
|
---|
27 | };
|
---|
28 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.