Skip to content

Instantly share code, notes, and snippets.

@kasper
Last active December 10, 2015 15:18
Show Gist options
  • Save kasper/4453365 to your computer and use it in GitHub Desktop.
Save kasper/4453365 to your computer and use it in GitHub Desktop.
Encapsulated JS Objects with Module Pattern
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