.
) Y notación de corchetes ( []
), similar a una matriz. La notación de puntos es lo que usa cuando conoce el nombre de la propiedad a la que intenta acceder con anticipación. Aquí hay una muestra del uso de la notación de puntos ( .
) Para leer la propiedad de un objeto: var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
testObj
usando la notación de puntos. Establezca la variable hatValue
igual al hat
propiedad del objeto y establezca la variable shirtValue
igual a la shirt
propiedad del objeto. hatValue
debe ser una cadena
testString: 'assert(typeof hatValue === "string" , "hatValue
should be a string");'
- text: El valor de hatValue
debe ser "ballcap"
testString: 'assert(hatValue === "ballcap" , "The value of hatValue
should be "ballcap"
");'
- text: shirtValue
debe ser una cadena
testString: 'assert(typeof shirtValue === "string" , "shirtValue
should be a string");'
- text: El valor de shirtValue
debe ser "jersey"
testString: 'assert(shirtValue === "jersey" , "The value of shirtValue
should be "jersey"
");'
- text: Deberías usar la notación de puntos dos veces.
testString: 'assert(code.match(/testObj\.\w+/g).length > 1, "You should use dot notation twice");'
```