function Father(name, age) {
this.name = name;
this.age = age;
}
function Son(name, age) {
Father.call(this, name, age);
}
Father.prototype.money = function() {
console.log('I have 100000$!');
}
Son.prototype = new Father();
Son.prototype.constructor = Son;
Son.prototype.habbit = function() {
console.log('I like playing!');
}
var grandSon = function(name,age,height){
Son.call(this,name,age)
this.height = height
}
grandSon.prototype = new Son()
grandSon.prototype.constructor = grandSon
grandSon.prototype.eat = () =>{
console.log("eat")
console.log(this)
}
var son = new Son('mmm', 17);
var father = new Father('cnm',123)
var grandson = new grandSon('cs',3,29)
console.log(father.__proto__.constructor)
father.money()
console.log(son.__proto__);
son.money();
son.habbit();
console.log(grandson.__proto__)
console.log(grandson.__proto__.__proto__)
console.log(grandson.__proto__.__proto__.__proto__)
console.log(grandson.__proto__.__proto__.__proto__.__proto__)
grandson.eat()
grandson.habbit()
grandson.money()
foo = {
init: function(name,label) {
this.name = name;
this.label = label;
},
myName: function() {
return "I am " + this.name;
}
};
Bar = Object.create( foo );
Bar.myLabel = function(){
return this.label;
};
var b1 = Object.create( Bar );
b1.init("a","obj a");
b1.myName();
b1.myLabel();