# 属性
12.1 访问属性时使用点符号. eslint:
dot-notation
(opens new window)const luke = { jedi: true, age: 28, }; // bad const isJedi = luke['jedi']; // good const isJedi = luke.jedi;
12.2 当获取的属性是变量时用方括号
[]
取const luke = { jedi: true, age: 28, }; function getProp(prop) { return luke[prop]; } const isJedi = getProp('jedi');
12.3 做幂运算时用幂操作符
**
。 eslint:no-restricted-properties
(opens new window).// bad const binary = Math.pow(2, 10); // good const binary = 2 ** 10;