This rule raises an issue when methods are accessed from empty instances like [] or {} instead of from their prototypes like Array.prototype or Object.prototype.

Why is this an issue?

When you need to "borrow" a method from built-in objects like Array or Object, accessing it through an empty instance is less clear and less efficient than accessing it directly from the prototype.

Creating empty instances like [] or {} just to access their methods introduces unnecessary object creation. This approach also makes the code less explicit about the intent - when you see [].slice.apply(), it’s not immediately clear that you’re borrowing the Array slice method.

Using Array.prototype.slice.apply() instead makes your intent crystal clear: you’re using the Array slice method on some other object. This pattern is commonly used when working with array-like objects (like arguments or NodeLists) that don’t have Array methods but can benefit from them.

The prototype approach is also more performant because it avoids creating temporary objects that will need to be garbage collected.

What is the potential impact?

This issue affects code readability and performance. While the performance impact is usually minimal, the clarity improvement is significant. Code that explicitly uses prototypes is easier to understand and maintain, especially for developers who may not be familiar with method borrowing patterns.

How to fix?

Replace empty array instances with Array.prototype when borrowing Array methods.

Non-compliant code example

const array = [].slice.apply(arrayLike); // Noncompliant

Compliant code example

const array = Array.prototype.slice.apply(arrayLike);

Documentation