JavaScript Authoritative Guide Note learning

Source: Internet
Author: User

    //returns a new object that inherits properties from the prototype object P    functioninherit (p) {if(p = =NULL)ThrowTypeError (); if(object.create) {returnobject.create (P); }        vart=typeofp; if(t!== "Object" &&t!== "function")ThrowTypeError (); functionf () {}; F.prototype=p; return Newf (); }

Property Access Error

Property access does not always return or set a value. Querying a non-existent property does not make an error, and if this attribute x is not found in either the property of the object o itself or the inherited property, the property access expression o.x returns undefine. Recall that our book object has the attribute "Sub-Title" and no Attribute "subtitle":

Book.subtitle undefined

Attempting to query the properties of this non-existent object will cause an error. Both null and undefined values have no properties, because the properties that query these values will report an error, as in the following example:

Throws a type error exception, undefined no Length property

var len=book.subtitle.length;

Unless the book and Book.subtitle are determined to be (or act on) the object. Otherwise, the expression book cannot be written like this. Subtitle.length, because this will be an error, here are two ways to avoid errors.

var len=undefined;

if (book) {

if (book.subtitle) len=book.subtitle.length;

}

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

Judging type

function classof (o) {if(o===null) {Retuen "null"}if(o===undefined) {return "Undefined"}return Object.prototype.toString (). Call (O). Slice (8,-1

 

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     

Assignment failed, but no error, object.prototype not modified

Delete Property

Delete operator,

Delete Book.author

Delete book["main title"]

JavaScript Authoritative Guide Note learning

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.