Permalink
Browse files

Returning and Exporting from Modules

  • Loading branch information...
1 parent 02e7b3a commit 187798a6f6047aca043e006981812b5d7e7d2415 @mwoods79 committed Apr 11, 2012
Showing with 37 additions and 0 deletions.
  1. +37 −0 README.md
View
@@ -45,4 +45,41 @@ Javascript.
// shows closure is not on global scope
console.log(closure); // ERRRRORRR
+## Immediate Functions and Modules
+1 Immediate Functions
+
+ // Some say module and immediate function are interchangable terms
+ (function(){
+ console.log("I get ran immidiately");
+ })();
+
+2 Returning or Exporting
+
+ // Returning Object Literals
+ var myModule = (function(){
+ var privateClosure = 0;
+ function voodoo(){
+ console.log("voodoo count: " + ++privateClosure);
+ // And I always return myself, when `new`
+ };
+ return {
+ voodoo: voodoo,
+ static: "Imma String, woopedy doo"
+ };
+ })();
+
+ myModule.voodoo();
+ myModule.voodoo();
+ myModule.voodoo();
+
+ // Returning Functions
+ var myModule = (function(){
+ function ImmaConstructor(){
+ console.log('I build stuff');
+ // And I always return myself, when `new`
+ };
+ return ImmaConstructor;
+ })();
+
+ new myModule();

0 comments on commit 187798a

Please sign in to comment.