minor
This commit is contained in:
parent
76b6eaf410
commit
746fe5f2b6
1 changed files with 3 additions and 2 deletions
|
@ -129,7 +129,7 @@ let key = "likes birds";
|
||||||
user[key] = true;
|
user[key] = true;
|
||||||
```
|
```
|
||||||
|
|
||||||
Here, the variable `key` may be calculated at run-time or depend on the user input. And then we use it to access the property. That gives us a great deal of flexibility.
|
Here, the variable `key` may be calculated at run-time or depend on the user input. And then we use it to access the property. That gives us a great deal of flexibility.
|
||||||
|
|
||||||
For instance:
|
For instance:
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ let key = prompt("What do you want to know about the user?", "name");
|
||||||
alert( user[key] ); // John (if enter "name")
|
alert( user[key] ); // John (if enter "name")
|
||||||
```
|
```
|
||||||
|
|
||||||
The dot notation cannot be used in a similar way.
|
The dot notation cannot be used in a similar way:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
let user = {
|
let user = {
|
||||||
|
@ -235,6 +235,7 @@ That can become a source of bugs and even vulnerabilities if we intend to store
|
||||||
In that case the visitor may choose `__proto__` as the key, and the assignment logic will be ruined (as shown above).
|
In that case the visitor may choose `__proto__` as the key, and the assignment logic will be ruined (as shown above).
|
||||||
|
|
||||||
There is a way to make objects treat `__proto__` as a regular property, which we'll cover later, but first we need to know more about objects.
|
There is a way to make objects treat `__proto__` as a regular property, which we'll cover later, but first we need to know more about objects.
|
||||||
|
|
||||||
There's also 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.
|
There's also 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.
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue