我有一個如此基本的JavaScript問題,我甚至不能製作一個適當的谷歌查詢來回答它。舉例來說:如何引用原型的父項?
function Parent(name){
this.name = name;
}
Parent.prototype.Child() = function(){
if(this.name == 'Sam'){ // This is the comparison that obviously doesn't work
/* Do something */
} else {
/* Do something else */
}
}
var Parent1 = new Parent('Sam');
var Child1 = new Parent1.Child();
是否有一個關鍵字可以在比較中用來代替這個來訪問Parent的「name」屬性?
乾杯!
'Parent.prototype.Child()= function(){'應該是'Parent.prototype.Child = function(){' – Musa