下面是我的JS代碼:繼承和壓倒一切的JavaScript
var Person=function(name,age)
{
this.name=name;
this.age=age;
}
Person.prototype.calculateAge=function()
{
console.log(2016-this.age);
}
var Teacher=function(salary)
{
this.salary=salary;
}
Teacher.prototype.calculateAge=function() // Ovverriding the fucntion calculateAge
{
console.log("welcome to my world");
}
var pp=new Person('john',31); // creating object pp, pp.name // john
Teacher.prototype=pp;
var t= new Teacher(20); // inherit name and age , t.name // john
// now here am confused
t.calculateAge() // 1990 but am ovverride it will print my console right
//
誰能請解釋我是如何可以重寫?在這裏,當我重寫計算年齡的函數,通過調用t.calculateAge()
其打印繼承一個
看到這個:https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance – ZAhmed
我檢查了這麼多的博客和視頻也困惑,我重寫calculateAge功能的權利,但是我打電話t.calculateAge(),它將打印latestone,但在這裏印刷的父母,我們在這種情況下如何ovverride,如何其workes –
改進的語言和做出格式更改 –