fixes
This commit is contained in:
parent
ab13ef8685
commit
0a2b936133
5 changed files with 41 additions and 34 deletions
|
@ -222,7 +222,11 @@ obj.__proto__ = 5;
|
|||
alert(obj.__proto__); // [object Object], didn't work as intended
|
||||
```
|
||||
|
||||
As we see from the code, the assignment to a primitive `5` is ignored. If we want to store *arbitrary* (user-provided) keys, then such behavior can be the source of bugs and even vulnerabilities, because it's unexpected. There's another data structure [Map](info:map-set-weakmap-weakset), that we'll learn in the chapter <info:map-set-weakmap-weakset>, which supports arbitrary keys.
|
||||
As we see from the code, the assignment to a primitive `5` is ignored.
|
||||
|
||||
That can be come a source of bugs and even vulnerabilies if we intent to store arbitrary key-value pairs in an object, and allow a visitor to specify the keys. In that case the visitor may choose "__proto__" as the key, and the assignment logic will be ruined (as shown above).
|
||||
|
||||
There's another data structure [Map](info:map-set-weakmap-weakset), that we'll learn in the chapter <info:map-set-weakmap-weakset>, which supports arbitrary keys. Also there's a way to make objects treat `__proto__` as a regular property, but first we need to know more about objects to understand it.
|
||||
````
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue