# unicorn/prefer-prototype-methods

> Require borrowing a method from the prototype instead of from an empty `[]` or `{}`

`[].slice.call(list)` creates an array only to reach `slice`, and then throws it away. `Array.prototype.slice.call(list)` names where the method comes from and creates nothing.

The rule reports a method of an empty `[]` or `{}` that's used with `.call()`, `.apply()` or `.bind()`, or passed as the first argument of `Reflect.apply()`.

`--fix` replaces `[]` with `Array.prototype` and `{}` with `Object.prototype`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/prefer-prototype-methods" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```js
const links = [].slice.call(document.links);
const isOwn = {}.hasOwnProperty.call(user, "name");
const first = Reflect.apply([].at, items, [0]);
```

Not reported:

{/* good */}
```js
const links = Array.prototype.slice.call(document.links);
const isOwn = Object.prototype.hasOwnProperty.call(user, "name");
const first = Reflect.apply(Array.prototype.at, items, [0]);
```

A method of any other object isn't reported:

{/* good */}
```js
const log = console.log.bind(console);
const all = [1, 2].concat.call(items, more);
```
