0
這裏我的問題,我不明白爲什麼這個覆蓋不要在這裏工作是源覆蓋方法在JavaScript
window.onload=function()
{
function Person(first,last)
{
this.First=first;
this.Last = last;
this.Full=function()
{
return this.First+" "+this.Last;
};
}
Person.prototype.GetFullName=function()
{
return this.First + " " + this.Last;
} ;
function Employee(first,last,position)
{
Person.call(this,first,last);
this.Position=position;
}
/* Employee.prototype = new Person();
var t = new Employee("Mohamed","Zaki","Web Developer");
alert(t.GetFullName());
*/
Employee.prototype.GetFullName=function()
{
var x = Person.prototype.GetFullName.call(this);
return x + " , " + this.Position ;
}
var e = new Employee("Mohamed","Zaki","Web Developer");
alert(e.GetFullName());
}
當我運行這個代碼(在添加了最後一個'}'後),它會發出警告'Web開發人員Mohamed Zaki。你在期待什麼? – 2012-04-13 04:02:23
我知道代碼正在工作,但我在評論中詢問代碼,爲什麼它不起作用? – tito11 2012-04-13 04:10:05
,因爲即使你設置了'this.Position = position',什麼都不讀。你期待它在GetFullName中嗎?也許你打算在評論中包含更多的代碼? – 2012-04-13 04:16:38