Last active
December 10, 2015 15:18
-
-
Save kasper/4453365 to your computer and use it in GitHub Desktop.
Encapsulated JS Objects with Module Pattern
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
var Foobar = function (foo) { | |
/* Private variables */ | |
var _foo = foo || 'default'; | |
/* Private functions */ | |
function magic() { | |
_foo = 'magic'; | |
} | |
/* Public functions */ | |
this.getFoo = function () { | |
return _foo; | |
} | |
this.setFoo = function (foo) { | |
_foo = foo; | |
magic(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment