Javascript examples for Data Type:Variable Scope
Expose local variables defined in anonymous function to the global space
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from w w w .j a va2 s .c o m*/ var module = (function () { var foo = 123; var bar = function () { console.log('Hallo'); }; return { foo: foo, bar: bar } })(); console.log(module.foo) module.bar(); } </script> </head> <body> </body> </html>