JavaScript object learning experience collation

  • 2020-03-26 21:25:55
  • OfStack

1. Object creation method :
(1) created by the new operator, followed by a constructor name
Var object = new object ();
When a constructor is called directly, it usually does not return a value; it simply initializes the object passed in by this value. But when used with new, it returns an object value as the value of the new expression

(2) object direct quantity
The direct object quantity consists of a list of property descriptions enclosed in braces separated by commas. Each property description of the object's direct quantity consists of the property name plus a colon and the property value, which can be of any type or a function
Var object = {a: 1, b: 'a', c: function(){}}

2. Setting and querying of object properties
(1) through the point operator object.p
(2) object['p']
Method 2 attributes are represented as strings to facilitate dynamic access to object attributes

3. Enumerate object properties
For (p in object) {
/ / do something
P is an attribute of object. This method can only enumerate user-defined attributes, not some predefined properties and methods, such as constructor

4. Access the undefined properties of the object and return undefined;

5. Object methods
Object method definition and access is similar to the object property, but the object method is a function; Within the method, the object that invokes the method through this reference

6. The prototype object of the object
(1) each object has a prototype object, which inherits all the properties of its prototype object; Property inheritance occurs only when the property value is read;
(2) the prototype of an object is defined by the constructor that creates and initializes the object;
(3) each function (constructor) has a prototype property that references the prototype object of the function

Related articles: