]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-proto.md
629cbbf9a9b3bf02955abd597ec86a6836d3d3e9
[pve-eslint.git] / eslint / docs / src / rules / no-proto.md
1 ---
2 title: no-proto
3 rule_type: suggestion
4 further_reading:
5 - https://johnresig.com/blog/objectgetprototypeof/
6 ---
7
8
9 `__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.
10
11 ## Rule Details
12
13 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`.
14
15 Examples of **incorrect** code for this rule:
16
17 ::: incorrect
18
19 ```js
20 /*eslint no-proto: "error"*/
21
22 var a = obj.__proto__;
23
24 var a = obj["__proto__"];
25
26 obj.__proto__ = b;
27
28 obj["__proto__"] = b;
29 ```
30
31 :::
32
33 Examples of **correct** code for this rule:
34
35 ::: correct
36
37 ```js
38 /*eslint no-proto: "error"*/
39
40 var a = Object.getPrototypeOf(obj);
41
42 Object.setPrototypeOf(obj, b);
43
44 var c = { __proto__: a };
45 ```
46
47 :::
48
49 ## When Not To Use It
50
51 You might want to turn this rule off if you need to support legacy browsers which implement the
52 `__proto__` property but not `Object.getPrototypeOf` or `Object.setPrototypeOf`.