Let's take a look at the inheritance of class inheritance and the blending of class inheritance and prototype inheritance, called Class inheritance, by using the call or Apply method to impersonate inheritance:
function Desk (size,height) {
this.size=size;
this.height=height;
}
function Mjdesk (size,height) {
desk.call (this,size,height);//This is called Class inheritance.
}
var mj = new Mjdesk (10,123);
Like above this is the class inheritance we want to use, with this inheritance, we can access the methods and properties in the class, but cannot access the methods and properties in the parent prototype, which, as the name suggests, is a false inheritance, so, of course, the fake can not inherit the real prototype, so, The disadvantage of class inheritance is also obvious, when we use more time, it will cause the waste of memory. Thus, we have a hybrid method of class inheritance and prototype inheritance:
function Desk (size,height) {
this.size=size;
this.height=height;
}
function Mjdesk (size,height) {
desk.call (this,size,height);//This is called Class inheritance.
}
Mjdesk.prototype=new Desk ()//prototype Inherits
var MJ = new Mjdesk (12,12);
Of course, the prototype inheritance here is better than using an empty function to inherit in our last chapter.
Of course, the most we are using now is the way to mix the two!
The above is a small set to introduce the JavaScript in the object of the inheritance relationship, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!