使用函數下面的代碼不工作:JavaScript的:我怎樣才能在一個構造
function CClass() {
myFunc(); //says it doesnt know about myFunc
}
CClass.prototype = {
myFunc: function() {}
};
的感謝!
使用函數下面的代碼不工作:JavaScript的:我怎樣才能在一個構造
function CClass() {
myFunc(); //says it doesnt know about myFunc
}
CClass.prototype = {
myFunc: function() {}
};
的感謝!
CClass.prototype.myFunc = function(){
alert("myFunc")
};
function CClass() {
this.myFunc();
}
c = new CClass()
myFunc
是不是在全球範圍內。
您應該使用
function CClass() {
this.myFunc();
}
你試圖做到這一點?
function CClass() {
this.myFunc()
}
CClass.prototype = {
myFunc: function() {
alert('hello from prototype');
}
};
var cc = new CClass(); // hello from prototype
我真的不明白你期望這段代碼做什麼。你能再解釋一下嗎? – Chris
你究竟想達到什麼目的? – fcalderan