属性
12.1 使用.
访问属性
eslint: dot-notation jscs: requireDotNotation
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
// bad
const binary = Math.pow(2, 10);
// good
const binary = 2 ** 10;