JavaScript Object Learning Experience Finishing _ Basics

Source: Internet
Author: User
Tags constructor
1. How objects are created :
(1) created by the new operator, followed by a constructor function name
var object = new Object ();
When a constructor calls directly, it usually does not return a value, it simply initializes the object passed in by the this value, but returns an object value as the value of the new expression when used with new

(2) Direct quantity of object
The object's direct amount consists of a list of attribute descriptions, which are enclosed in curly braces, where the attribute descriptions are separated by commas. Each attribute description of the object's direct quantity consists of a property name plus a colon and a property value, which can be any type or function
var object = {a:1, B: ' A ', C:function () {}}

2. Settings and queries for object properties
(1) OBJECT.P by dot operator
(2) class array mode object[' P ']
Method 2 property is represented by a string, which facilitates dynamic access to object properties

3. Enumerating Object Properties
For (p in object) {
Do something
}
P is an object attribute, which can only enumerate user-defined attributes, and cannot enumerate certain predefined properties and methods, such as constructor

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

5. Object method
object's method definition and access is similar to the object property, except that the object method is a function and the object of the method is called through this reference inside the method

6. object's Prototype Object
(1) Each object has a prototype object, which inherits all the attributes of its prototype object; The inheritance of the property 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 object that has a prototype property reference function

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.