Skip to content

Instantly share code, notes, and snippets.

@telamon
Created February 24, 2012 13:05
Show Gist options
  • Save telamon/1900799 to your computer and use it in GitHub Desktop.
Save telamon/1900799 to your computer and use it in GitHub Desktop.
JavaScript web library pattern
(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