//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