Skip to content

Prefer borrowing methods from the prototype instead of the instance

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

When “borrowing” a method from Array or Object, it's clearer to get it from the prototype than from an instance.

Fail

js
const array = [].slice.apply(bar);
js
const type = {}.toString.call(foo);
js
Reflect.apply([].forEach, arrayLike, [callback]);
js
const type = globalThis.toString.call(foo);

Pass

js
const array = Array.prototype.slice.apply(bar);
js
const type = Object.prototype.toString.call(foo);
js
Reflect.apply(Array.prototype.forEach, arrayLike, [callback]);
js
const maxValue = Math.max.apply(Math, numbers);

Released under the Apache License 2.0.