Skip to content

functionApplySpreads

Prefer the spread operator over .apply() calls.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Before ES2015, one had to use Function.prototype.apply() to call variadic functions with an array of arguments. In ES2015 and later, the spread operator (...) provides cleaner syntax for the same purpose.

This rule flags usage of .apply() when it can be replaced with spread syntax. It only reports cases where the this argument is not changed, meaning the spread replacement is safe.

53fAB0app5<3(sp ansty="le--0:#82AAFF;--1:#3B61">B0undefin53, args<);d ivclassNa="meco"><);d>53fAB0app5<3(sp ansty="le--0:#FF6A83;--1:#A248">48nu53, args<);d ivclassNa="meco"><);d>53oA11fAB0app53(obj, args<);d ivclassNa="meco"><);d>53MaA11mAB0app53(Math, numbers<);d ivclassNa="meco"><);d>
61B<0foo spans="tyle--0:#D6DEEB;--1:#40">36E7<2... spans="tyle--0:#D6DEEB;--1:#40">3F53ar<;di vdivclass="Nameexpressive-">3F5<3obj spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0foo spans="tyle--0:#D6DEEB;--1:#40">36E7<2... spans="tyle--0:#D6DEEB;--1:#40">3F53ar<;di vdivclass="Nameexpressive-">3F534<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0max spans="tyle--0:#D6DEEB;--1:#40">36E7<2... spans="tyle--0:#D6DEEB;--1:#40">3F53numbe<;di vdivclass="Nameexpressive-">3F5<3foo spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0a3F53(otherThis, ar<;di vdivclass="Nameexpressive-">3F5<3foo spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0a348483F5<3, [ spans="tyle--0:#F78C6C;--1:#AA">0<9821 spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#F78C6C;--1:#AA">0<9822 spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#F78C6C;--1:#AA">0<9823 spans="tyle--0:#D6DEEB;--1:#40">3F5<3]) ;divclass="Name"><3])>

This rule is not configurable.

This rule should not be used if you need to target ES5 or earlier JavaScript environments that don’t support the spread operator.

If you have code that intentionally uses .apply() for readability or other reasons, you may want to disable this rule.