Skip to content

Instantly share code, notes, and snippets.

@shikolay
Forked from paulobsf/ModulePattern.js
Created October 30, 2012 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shikolay/3977772 to your computer and use it in GitHub Desktop.
Save shikolay/3977772 to your computer and use it in GitHub Desktop.
JavaScript Module Pattern
/*
* Source: http://www.jeremyjohnstone.com/blog/2007-12-27-useful-javascript-oo-pattern.html/comment-page-1#comment-88
*/
var myObj = function() {
// private instance variables
var foo = 33;
// pseudo static initializer
var staticInitializer = function() {
// do some code here, will run only once
}();
// private method
function foobar() {
// do something
}
// public api
return {
publicMethod: function() {
// do something
},
publicVariable: 42,
publicMethod2: function() {
// do something
}
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment