我有html5得分基础游戏。当游戏结束时,结束屏幕通过以下功能显示总分:
this.show = function (a)
{
b.text = TEXT_GAMEOVER;
e.text = TEXT_SCORE + ": " + a;
d.visible = !0;
};
现在我想在onclick按钮释放功能中获得a
或e.text
的总分:
var a;
this._onButSendRelease = function ()
{
console.log(a);
}
但是a
未定义,请帮助我如何做到这一点。
答案 0 :(得分:1)
您只需将分数存储在全局范围内声明的变量中:
var score; //Declare your variable here
this.show = function (a)
{
b.text = TEXT_GAMEOVER;
e.text = TEXT_SCORE + ": " + a;
score = a; //Populate your variable here
d.visible = !0;
};
this._onButSendRelease = function ()
{
console.log(score); //Display your variable here
}