12. 属性

最后更新于:2022-04-01 21:12:24

* [12.1](https://github.com/yuche/javascript#12.1) 使用 `.` 来访问对象的属性。 ~~~ const luke = { jedi: true, age: 28, }; // bad const isJedi = luke['jedi']; // good const isJedi = luke.jedi; ~~~ * [12.2](https://github.com/yuche/javascript#12.2) 当通过变量访问属性时使用中括号 `[]`。 ~~~ const luke = { jedi: true, age: 28, }; function getProp(prop) { return luke[prop]; } const isJedi = getProp('jedi'); ~~~
';