Created
February 24, 2012 13:05
-
-
Save telamon/1900799 to your computer and use it in GitHub Desktop.
JavaScript web library pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ // Wrap everything up in a function | |
var count,person; // These become private to this wrapped scope, and do not clutter the global namespace. | |
count=0; // Modify private count var, | |
person= function(name){ | |
this.name = name; | |
count++; | |
this.countPeople = function(){ | |
return count; | |
} | |
} | |
window.Person = person; // Export my person and make it reachable through window.Person; | |
})(); // Execute the wrapped code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment