design patterns - Javascript: How can two self executing function access each other -


i javascript self executing anonymous function is:

(function(){     console.log('hello world!'); })(); 

and can pass in parameters:

(function(window){    window.location(...); })(window); 

but if have 2 self executing anonymous functions, can each 1 access other? specifically, how can first function call method second, passing variable?

(function(){     function foo () {         return 'foo';     }      // how can call "bar('my name is')" })();  (function(){     function bar (str) {         return str + ' bar' ;     } })(); 

thanks listening.

they can't , that's kinda point. wrapping code this, inaccessible outside.

if don't care such accessibility protections other things is:

function foo() { bar() } // call bar foo(); // execute function bar() { // stuff } bar(); // execute 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -