Created
September 27, 2014 19:53
-
-
Save ryanseys/2b2caf8484091025d4be to your computer and use it in GitHub Desktop.
Privileged methods
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
/** | |
* 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