Understanding Scope on Javascript -


i'm understanding "scope" found code, im wondering how can execute "inner" function, tried this:

outer().inner();

but doesn't works

        /* global scope */         var local = true;         var global = true;         function outer() {             /* local scope */             var local = true;             var global = false;              /* nearest scope = outer */             local = !global;             console.log("local: "+local);             console.log("global: "+global);              function inner() {                 /* nearest scope = outer */                 local = false;                 global = false;                  /* nearest scope = undefined */                 /* defaults defining global */                 public = global;             }         } 

you change outer object instead of function.

/* global scope */ var local = true; var global = true; var outer = {     /* local scope */     local : true,     global : false,      /* nearest scope = outer */     local : !global,      showlogs: function(){         console.log("local: "+local);         console.log("global: "+global);     },      inner: function(){         local = false;         global = false;         public = global;     } } 

notice i'm declaring outer object instead of function var outer={} way can call functions outer.inner(); , outer.showlogs();


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -