Skip to content

Instantly share code, notes, and snippets.

@zhannes
Last active December 12, 2015 10:38
Show Gist options
  • Save zhannes/4760091 to your computer and use it in GitHub Desktop.
Save zhannes/4760091 to your computer and use it in GitHub Desktop.
avoid globals, use a namespace
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<script src="js/module-1.js"></script>
<script src="js/module-2.js"></script>
</body>
</html>
(function(App){
console.log('params to module #1 \n');
console.log(App);
console.log('\n exporting a property from inside module 1 \n');
App.someThing = 'bar';
}).call(
this,
this.App || (this.App = {})
);
(function(App){
console.log('\n inside module 2 \n\n');
console.log(App);
}).call(
this,
this.App || (this.App = {})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment