Skip to content

Latest commit

 

History

History
30 lines (20 loc) · 770 Bytes

prefer-reflect-apply.md

File metadata and controls

30 lines (20 loc) · 770 Bytes

Prefer Reflect.apply() over Function#apply()

Reflect.apply() is arguably less verbose and easier to understand. In addition, when you accept arbitrary methods, it's not safe to assume .apply() exists or is not overridden.

This rule is fixable.

Fail

function foo() {}

foo.apply(null, [42]);
Function.prototype.apply.call(foo, null, [42]);
foo.apply(this, [42]);
Function.prototype.apply.call(foo, this, [42]);
foo.apply(null, arguments);
Function.prototype.apply.call(foo, null, arguments);
foo.apply(this, arguments);
Function.prototype.apply.call(foo, this, arguments);

Pass

function foo() {}

Reflect.apply(foo, null, [42]);