使用函数下面的代码不工作: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