Created
December 20, 2013 04:11
-
-
Save pdswan/8050324 to your computer and use it in GitHub Desktop.
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
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