TreeviewCopyright © aleen42 all right reserved, powered by aleen42

Spread Operator Back

In ES6, Spread Operator ... is used to spread an array into more than one arguments:

/** method call */
myFunction(...args)
/** array literal */
[...iteralObject, 4, 5, 6]

So far, in ES5, we will use Function.prototype.apply to spread an array into more than one arguments:

function myFunction(x, y, z) {}

var args = [0, 1, 2];
myFunction.apply(null, args);

But in ES6, you can code like this:

function myFunction(v, w, x, y, z) {}

var args = [0, 1];
myFunction(-a, ...args, 2, ...[3]);

Powerful Array Literal

With Spread Operator, we can code less to add attributes to an array:

var parts = ['shoulder', 'knee'];
var body = ['head', ...parts, 'legs'];  /** => ['head', 'shoulder', 'knee', legs'] */
Empty Comments
Sign in GitHub

As the plugin is integrated with a code management system like GitLab or GitHub, you may have to auth with your account before leaving comments around this article.

Notice: This plugin has used Cookie to store your token with an expiration.