function FakeClass(){};
FakeClass.prototype.someMethod = function(){};
FakeClass.prototype.otherMethod = function(){
//need to call someMethod() here.
}
我需要从otherMethod调用someMethod,但显然它不起作用。如果我将它构建为单个函数(不是原型),我可以调用它,但调用prototyped不起作用。我怎么能这样做,就好像我正在像一个类的方法对待函数?如何从原型“类”中调用原型函数?
更新: 我打电话的方法触发一个jQuery事件之后。它会影响整个事物的行为方式吗?
function CicloviarioEngine(){};
CicloviarioEngine.prototype.test = function(){
alert("Hey");
}
CicloviarioEngine.prototype.initialize = function(){
$('#add-route').click(function(){
this.test(); //doesn't work
CicloviarioEngine.test(); //doesn't work
externalTest(); //works
});
}
function externalTest(){
alert("externalTest()");
}
工作正常。谢谢!并且谢谢@CMS。 – 2010-05-01 23:30:24