Created
October 22, 2018 09:43
-
-
Save nelsonfncosta/1e5b2eebceff6db263bf7ca9f6f98756 to your computer and use it in GitHub Desktop.
JS private variable
This file contains hidden or 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 Container(param) { | |
let secret = 3; | |
let that = this; | |
this.member = param; | |
function dec() { | |
if (secret > 0) { | |
secret -= 1; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
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