How to make a global variable jquery?

0

I have this following variable:

Site = {
   Alert: function(titulo, conteudo, data){
      var id = Math.round(Math.random()*10000);
   }
}

I would like to access it anywhere in my code, specifically here:

User = {
   ConfirmSair: function(){
      alert(id);
   }
}

How can I do this?

    
asked by anonymous 30.07.2017 / 22:21

1 answer

-1

Instead of var id use window.id , or a more secure name not to be overwritten as window.randomId .

This type of programming is inadvisable because it generates code that is difficult to maintain, read, and is conducive to overwriting that variable elsewhere in the code and you do not know where this is happening.

But if you need to get the suggestion as indicated above.

    
30.07.2017 / 22:44