我有一个类似的东西(按钮)。实例化它时,我将onClick函数作为参数传递给它的构造函数。为了响应点击,我希望按钮实例"停用()"要调用的方法。如何从函数pass-as-argument中正确引用该方法?
button = function(onclick){
this.deactivate = function(){
activeButton = null;
}
this.onclick = function(){onclick()};
}
var makeMainMenu = function(){
this.multiplayerButton = new button(function(e){
//onClick function of multiplayerButton:
mainMenu.multiplayerButton.deactivate(); //HELP HERE
selectDifficultyMenu = makeSelectDifficultyMenu();
mainMenu.all.hide();
});
}
mainMenu = makeMainMenu();