Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.01 KB

prefer-prototype-methods.md

File metadata and controls

42 lines (30 loc) · 1.01 KB

Prefer borrowing methods from the prototype instead of the instance

This rule is part of the recommended config.

🔧 This rule is auto-fixable.

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 hasProperty = {}.hasOwnProperty.call(foo, 'property');
Reflect.apply([].forEach, arrayLike, [callback]);

Pass

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