JavaScript (5) prototype chain (Evernote)

Source: Internet
Author: User
Tags hasownproperty

1. Simple prototype chain: var song= function () {
THIS.A = 5;
this.b=6;
}//function Song () {this.a=5;}
song.prototype={
Add:function (A, b) {return a+b+this.a+this.b;},
Jian:function (A, b) {return b-a;}
}
var jum= function () {
This.name= "WTF";
}
Jum.prototype=new song ();//Let the Jum class inherit an instance of Song (including properties and methods) if you only want to song method, keep its properties of the private nature, you can set Jum.prototype =song.prototype;

Jum.prototype.constructor=jum; If it does not point to itself, then prototype.constructor points to an empty object invocation method: var songjum= new Jum (); Songjum.add (3,4); Songjum.jian (2,5); 2. Property Lookup: The property looks for its own properties, and if no more prototypes are found, no more, then go up and stick to the prototype of object. 3.hasOwnProperty
var foo = {
Hasownproperty:function () {
return false;
},
Bar: ' Here is Dragons '
};

Foo.hasownproperty (' Bar '); Always returns false

Use the {} object's hasOwnProperty and set it up and down to Foo
{}.hasownproperty.call (foo, ' Bar '); True

JavaScript (5) prototype chain (Evernote)

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.