JavaScript authoritative design--javascript object (brief study note eight)

Source: Internet
Author: User

1. Attributes of PropertiesA property consists of a name and 4 attributes. 4 Properties: Value, writable, enumerable, configurable  2. Three properties of an object One: Prototype propertiesto detect whether an object is a prototype of another object, use the isPrototypeOf () methodsuch as:
var P={x=1};    // defining a prototype object var o=object.create (p);    // Use this prototype object to create an object p.isprototypeof (o)    //True:o inherits from Pobject.isprototypeof (p)    // True:p inherited from Object.prototype
  two: Class propertiesDetermine Class Property function: Classof ()
function classof (o) {    if(o===null) {        return ' null ';    }     if (o===undefined) {        return "undefined";    }     return    Object.prototype.toString.call (o). Slice (8,-1);}
Run:
Classof (null)    //"null"classof (1)    //"number"classof ("")    //"String"classof (new F ())    // "Object"classof (windoe)    //"window" (This is the client host object)
  Three: scalabilitythe extensibility of the object indicates whether a new property can be added to the object. all built-in objects and custom objects in ECMASCRIPT5 are extensible. The purpose of extensibility is to "lock" the object to avoid outside interference. use object.esextensible () to determine whether an object is extensible. use object.preventextensible () to convert the object to non-extensible. Once an object is converted to non-extensible, it cannot be converted to extensible.   Four: Serializing Objectsserialization refers to converting the state of an object to a string, or to restoring a string to an object. ECMASCRIPT5 provides built-in functions json.stringify () and json.parse () such as:
o={    x:1,    y:{        z:[false,null, ""]        }}s=json.stringify (o)    // ' {"x": 1, "Y": {"Z": [False,null, ""]} 'P=json.parse (s)    // p is a deep copy of O

JavaScript authoritative design--javascript object (brief study note eight)

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.