Access outer members in Javascript module -


i have module

something = {     value : "",     anotherval : "",     method : function(){            this.anotherval = "i think accessable here";            global.action(            func : function(){                // in here want access above value.                // property of outer module.                <![magicoccurshere]!>.value = "magically access outer scope"            });     } } 

as can see above code access property on level of scope outside of this using magicaoccurshere...

i have done before making module return function not json object , naming each level. dislike syntax.

something = new something(); = function something() {     var bigdaddy = this;     this.value = "";     this.anotherval = "";     this.method = function(){            bigdaddy.anotherval = "set 1 of big daddies vars";            global.action(            func : function(){                // in here want access above value.                // property of outer module.                bigdaddy.value = "can still set 1 of big daddies vars"            });     } } 

i may missing point here , if point me it, happy read.

am being harsh on messy pattern , code of option 2?

if create local variable inside method function, in scope in inner func:

var = {     value : "",     anotherval : "",     method : function(){            var obj = this;            this.anotherval = "i think accessable here";            global.action(            func : function(){                // in here want access above value.                // property of outer module.                obj.anotherval = "magically access outer scope"            });     } } 

or can use qualified path:

var = {     value : "",     anotherval : "",     method : function(){            this.anotherval = "i think accessable here";            global.action(            func : function(){                // in here want access above value.                // property of outer module.                something.anotherval = "magically access outer scope"            });     } } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -