Prototypical Inheritance
Code Example:
function demo(a){
this.a=a;
}
function sample(){
demo.call(this,20);
this.b=10;
}
var x = new sample();
console.log(x.a)
Classical Inheritance:
Code Example:
function demo(){
this.a=10;
}
function sample(){
this.x=demo();
this.x();
this.b=10;
}
var x = new sample();
console.log(x.a)
Prototype Inheritance
Code Example:
function demo(){
this.a=20;
}
function sample(){
this.b=10;
}
sample.prototype=new demo();
var x = new sample();
console.log(x.a)
No comments:
Post a Comment