scope - Access a javascript variable from a function inside a variable -


hello have following issue not quite sure how search it:

function(){     var sites;      var controller = {       list: function(){         sites = "some value";       }     }   } 

so question how access sites variable top defined

var sites

edit:

here more complete part. using marionette.js. don't want define variable attached module (code below) variable keep private module, hope makes sense. here code works:

admin.module("site", function(module, app, backbone, marionette, $, _ ) {    module.sites = null;    module.controller = {     list: function (id) {       module.sites = app.request("site:entities");     }   }; }); 

and instead of

module.sites=null;

to

var sites;

that sort of thing make difference right? because in first case defining accessible variable outside second case private one. bit new javascript please try make simple.

if looking global access, declare variable outside function first, make changes variable inside function, can value whenever need it.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -