Created
March 29, 2012 14:25
-
-
Save kedde/2237945 to your computer and use it in GitHub Desktop.
JavaScript: Module pattern - exapmle (public and private methods and private properties)
This file contains 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
/// | |
/// 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