.
) E notação de colchetes ( []
), semelhante a uma matriz. A notação de pontos é o que você usa quando sabe o nome da propriedade que está tentando acessar antecipadamente. Aqui está uma amostra de uso de notação de ponto ( .
) Para ler a propriedade de um objeto: var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
testObj
usando a notação de ponto. Defina a variável hatValue
igual ao hat
propriedade do objeto e defina a variável shirtValue
igual à shirt
propriedade do objeto. hatValue
deve ser uma string
testString: 'assert(typeof hatValue === "string" , "hatValue
should be a string");'
- text: O valor de hatValue
deve ser "ballcap"
testString: 'assert(hatValue === "ballcap" , "The value of hatValue
should be "ballcap"
");'
- text: shirtValue
deve ser uma string
testString: 'assert(typeof shirtValue === "string" , "shirtValue
should be a string");'
- text: O valor de shirtValue
deve ser "jersey"
testString: 'assert(shirtValue === "jersey" , "The value of shirtValue
should be "jersey"
");'
- text: Você deve usar a notação de ponto duas vezes
testString: 'assert(code.match(/testObj\.\w+/g).length > 1, "You should use dot notation twice");'
```