从其他功能中获取价值 - Javascript

时间:2018-03-02 16:11:01

标签: javascript html5

我有html5得分基础游戏。当游戏结束时,结束屏幕通过以下功能显示总分:

this.show = function (a)
{
    b.text = TEXT_GAMEOVER;
    e.text = TEXT_SCORE + ": " + a;
    d.visible = !0;
};

现在我想在onc​​lick按钮释放功能中获得ae.text的总分:

var a;
this._onButSendRelease = function ()
{ 
       console.log(a);
}

但是a未定义,请帮助我如何做到这一点。

1 个答案:

答案 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
}