Chapter 3 objects
3.1 simple JavaScript types include numbers, strings, Boolean values (true and false), null values, and undefined values. All other values are objects.
3.2. Objects in JavaScript are variable key sets. In JavaScript, arrays are objects, functions are objects, regular expressions are objects, and objects are objects.
3.3. An object is a property container. Each property has a name and a value. The attribute name can be any string including an empty string. The attribute value can be any value except the undefined value.
3.4. You can use [] or [] to retrieve the value contained in an object. (the premise is that the attribute string is a constant and a valid JavaScript identifier is not a reserved word. representation, because it is more readable.
var Person = {"first-name" : "Zhang","middle-name" : "Yi","last-name" : "Mou",'age' : 60,}Person["first-name"]; // ZhangPerson.age; // 60
3.5, | operator can be used to fill the default value:
var middleName = Person["middle-name"] || "none";var tel = Person.tel || "unknown";
3.7. The & operator can be used to avoid typeerror exceptions caused by an undefined value.
Person.tel // undefinedPerson.tel.number// throw "TypeError"Person.tel && Person.tel.number // undefined
3.8 objects are passed through references, and they will never be copied.
VaR A ={}, B ={}, C ={}; // A, B, and C each references a different empty object a = B = C = {}; // A, B, and C all reference the same empty object
3.9. Each object can be connected to a prototype object and can inherit attributes from it. All objects created through object literal are linked to the standard object in JavaScript Object. prototype.
3.10 The prototype connection does not work during update. when an object is changed, the prototype of the object is not touched.
3.11 prototype connections can only be used when retrieving values. If we try to get a value of an object without the property name, JavaScript will try to get the property value from its prototype object. If the prototype object does not have this attribute value, search for it from its prototype, and so on to know that the process finally reaches the destination object. prototype. If the desired attribute does not exist in the prototype chain, the result is the undefined value. This process becomes"Delegate".
3.12. The hasownproperty () method is used to retrieve the unique attributes of an object. If true is returned, the prototype chain is not checked.
3.13 The for in statement can traverse all attribute names in the object, including the prototype chain. The hasownproperty method or typeof method can be used as a filter.
3.14. The delete operator is used to delete object attributes, but does not touch any objects in the prototype chain.
3.15 one way to minimize the use of global variables is to create only one unique global variable in your application:
var MYAPP = {};
The variable becomes the application container:
MYAPP.Person = { ... };MyApp.Weather = { ... };
(End)
Reprinted please indicate the source: http://blog.csdn.net/xxd851116/article/details/7664502