.),一个是中括号操作符([])。
当你知道所要读取的属性的名称的时候,使用点操作符。
这是一个使用点操作符读取对象属性的例子:
```js
var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
```
testObj,把hat的属性值赋给变量hatValue,把shirt的属性值赋给shirtValue。
hatValue应该是一个字符串。
testString: assert(typeof hatValue === 'string' );
- text: hatValue的值应该是"ballcap"。
testString: assert(hatValue === 'ballcap' );
- text: shirtValue应该是一个字符串。
testString: assert(typeof shirtValue === 'string' );
- text: shirtValue的值应该是"jersey"。
testString: assert(shirtValue === 'jersey' );
- text: 你应该使用点操作符两次。
testString: assert(code.match(/testObj\.\w+/g).length > 1);
```