Skip to content

Commit

Permalink
Docs: updated no-proto rule (fixes #11743) (#11746)
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime authored and aladdin-add committed May 23, 2019
1 parent 15c6c63 commit e45cc3f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions docs/rules/no-proto.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Disallow Use of `__proto__` (no-proto)

`__proto__` property has been deprecated as of ECMAScript 3.1 and shouldn't be used in the code. Use `getPrototypeOf` method instead.
`__proto__` property has been deprecated as of ECMAScript 3.1 and shouldn't be used in the code. Use `Object.getPrototypeOf` and `Object.setPrototypeOf` instead.

## Rule Details

When an object is created `__proto__` is set to the original prototype property of the objects constructor function. `getPrototypeOf` is the preferred method of getting "the prototype".
When an object is created with the `new` operator, `__proto__` is set to the original "prototype" property of the object's constructor function. `Object.getPrototypeOf` is the preferred method of getting the object's prototype. To change an object's prototype, use `Object.setPrototypeOf`.

Examples of **incorrect** code for this rule:

Expand All @@ -14,6 +14,10 @@ Examples of **incorrect** code for this rule:
var a = obj.__proto__;

var a = obj["__proto__"];

obj.__proto__ = b;

obj["__proto__"] = b;
```

Examples of **correct** code for this rule:
Expand All @@ -22,11 +26,16 @@ Examples of **correct** code for this rule:
/*eslint no-proto: "error"*/

var a = Object.getPrototypeOf(obj);

Object.setPrototypeOf(obj, b);

var c = { __proto__: a };
```

## When Not To Use It

If you need to support legacy browsers, you might want to turn this rule off, since support for `getPrototypeOf` is not yet universal.
You might want to turn this rule off if you need to support legacy browsers which implement the
`__proto__` property but not `Object.getPrototypeOf` or `Object.setPrototypeOf`.

## Further Reading

Expand Down

0 comments on commit e45cc3f

Please sign in to comment.