JavaScript authoritative Guide Notes (6th Chapter object)

Source: Internet
Author: User

1. Overview of objects

1. Common usage of objects:

Create, set, Query, delete, test, enumerate

2. Attribute properties of the object:

Writable, enumerable, configurable

3. Object properties for each object:

Prototypes, Class of objects, extensibility of objects

4. Object and attribute classification:

Built-in objects, host objects, custom objects, free attributes, inherited properties

2. Create objects

1. Direct volume of objects

2. Create an object from new

3. Prototypes

4, Object.create ()

First parameter: The prototype of this object

Second parameter: Optional, further description of the properties of the object

var // O1 inherits Properties X and Y. var o2 = Object.create (null//  O2 inherits no props or methods. var // O3 is a like {} or New Object ().

generic inherit () function, compatible version (but not completely replace create if the second parameter cannot be accepted)

functioninherit (p) {if(p = =NULL)ThrowTypeError ();//p must be a Non-null object    if(object.create)//If object.create () is defined ...    returnObject.create (P);//Then just use it.    vart =typeofP//Otherwise do some more type checking    if(t!== "Object" && t!== "function")ThrowTypeError (); functionF () {};//Define a dummy constructor function.F.prototype = p;//Set its prototype property to P.    return Newf ();//Use f () to create an "heir" of P.}

3. Query and settings for attributes

1. Object as an associative array

JavaScript objects are associative arrays, the difference between point access and parenthesis access

2. Inheritance

3. Property Access Error

var len = Book && book.subtitle && book.subtitle.length;

The purpose of this code: to avoid property access errors

The following scenario causes the object o to set the property p to fail:

1, the attribute p in O is read-only

2, o the attribute p is inherited, and is read-only: cannot overwrite the inherited property of a read-only property through its own property

3.

JavaScript authoritative Guide Notes (6th Chapter object)

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.