Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 1.04 KB

prefer-prototype-methods.md

File metadata and controls

46 lines (32 loc) · 1.04 KB

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

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

Pass

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