search

Home  >  Q&A  >  body text

javascript - How to get the variable value in the variable in the function from the outside

How to get the variable value inside the function from outside the function?

function time(){
      var date=''2017'';
}
alert(date);
曾经蜡笔没有小新曾经蜡笔没有小新2749 days ago668

reply all(5)I'll reply

  • PHP中文网

    PHP中文网2017-05-18 11:00:18

    Define global variables, write variable declarations outside the function, and use them directly inside the function

    var data;
    function time(){
        data="2017";
    }
    alert(data)

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-18 11:00:18

    Just return it and it will be fine

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-18 11:00:18

    It is recommended that the questioner read the relevant knowledge about the scope of variables, which may be of great help.

    reply
    0
  • 怪我咯

    怪我咯2017-05-18 11:00:18

    localStorage

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-18 11:00:18

    var time = function(){
        this._date = '2017';
    }
    var fn = new time;
    console.info(fn._date);

    reply
    0
  • Cancelreply