Skip to content

Instantly share code, notes, and snippets.

@kedde
Created March 29, 2012 14: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 kedde/2237945 to your computer and use it in GitHub Desktop.
Save kedde/2237945 to your computer and use it in GitHub Desktop.
JavaScript: Module pattern - exapmle (public and private methods and private properties)
///
/// Module patttern - exapmle
/// * public and private methods
/// * private properties
///
var moduleInJavascript = function () {
// private property
var privateProperty = {
property: ["some", "thing", "stuff"]
};
// private method
function privateMethod(obj, parameter) {
obj.something = parameter;
}
return {
// public method
publicMethod: function (linkObj, parameter) {
privateMethod(linkObj, parameter);
},
// public method
init: function () {
var self = this; // assign reference to current object to "self"
// access property and methods:
var prop = privateProperty.property[1];
self.publicMethod(this, prop);
}
};
} ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment