Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 967 Bytes

no-rest-spread-parameter.md

File metadata and controls

30 lines (21 loc) · 967 Bytes

Disallow usage of the rest parameter syntax (no-rest-spread-parameter)

The rest parameter and spread operator syntax were introduced in ES6. In older browsers, this syntax is transpiled down to ES5. The resulting code loops over arguments to create a new array object, which causes performance issues. If your app supports older browsers, copy arguments using Array.prototype.slice instead.

Rule details

Examples of incorrect code:

// rest
function foo(...args) {
    console.log(args);
}

// spread
const arr = ['foo', ...otherArr];

Examples of correct code:

const ArraySlice = Array.prototype.slice;

function foo() {
    const args = ArraySlice.call(arguments, 0);
    console.log(args);
}

const arr = ['foo'].concat(otherArray);