JavaScript Object learning experience

Source: Internet
Author: User

1. Object Creation Method:
(1) It is created through the new operator, followed by a constructor name.
Var object = new Object ();
When a constructor calls a function directly, it usually does not return a value. It only initializes the object passed in by the this value. However, when used with new, an object value is returned as the value of the new expression.

(2) direct object quantity
The object quantity is composed of the attribute description list, which is included in braces. The attribute description is separated by commas. Each attribute description of an object's direct quantity is composed of a colon and a property value. The property value can be of any type or function.
Var object = {a: 1, B: 'A', c: function (){}}

2. Set and query object attributes
(1) object. p through the vertex Operator
(2) object ['P']
Method 2 attributes are represented by strings to facilitate dynamic access to Object Attributes

3. enumerate Object Attributes
For (p in object ){
// Do something
}
P is an object attribute. In this method, only user-defined attributes can be listed, and some predefined attributes and methods cannot be listed, such as constructor.

4. The undefined attribute of the access object is returned;

5. Object Methods
The method definition and access of an object are similar to object properties, but the object method is a function. The object that calls a method through this inside the Method

6. Prototype object of the object
(1) Each object has an original object that inherits all attributes of its prototype object. property inheritance only occurs when the attribute 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 attribute that references the prototype object of the function.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.