Skip to content

Instantly share code, notes, and snippets.

@pdswan
Created December 20, 2013 04:11
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 pdswan/8050324 to your computer and use it in GitHub Desktop.
Save pdswan/8050324 to your computer and use it in GitHub Desktop.
function Foo(options) {
var privateInstanceVar = options.thing;
var publicInstanceVar = options.otherThing;
var publicInterface = {
publicFunction: publicFunction,
publicInstanceVar: publicInstanceVar
};
return publicInterface;
function publicFunction() {
/* privateInstanceVar
is accessible within the closuer */
if (privateInstanceVar) {
privateFunction();
}
}
function privateFunction() {
/* ... */
}
}
var instance = Foo({ thing: "foo", otherThing: "bar" });
var otherInstance = new Foo({ thing: "foo", otherThing: "bar" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment