Skip to content

Instantly share code, notes, and snippets.

@ryanseys
Created September 27, 2014 19:53
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 ryanseys/2b2caf8484091025d4be to your computer and use it in GitHub Desktop.
Save ryanseys/2b2caf8484091025d4be to your computer and use it in GitHub Desktop.
Privileged methods
/**
* Privileged methods.
*
* From http://www.crockford.com/javascript/private.html
*/
function Container(param) {
function dec() {
if (secret > 0) {
secret -= 1;
return true;
} else {
return false;
}
}
this.member = param;
var secret = 3;
var that = this;
this.service = function () {
return dec() ? that.member : null;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment