Created
May 1, 2015 20:25
-
-
Save cyc115/371b45d0f104c4e6b65a to your computer and use it in GitHub Desktop.
js private memeber variable
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
//javascript private variable | |
var counterCreater = function() { | |
// constructor | |
function Counter () { | |
var count = 0 ; // private | |
this.inc = function () { | |
count++; | |
console.log("inc:" + count); | |
} | |
this.get = function(){ | |
console.log("get:" + count); | |
return this.count; | |
} | |
this.reset = function(){ | |
count = 0 ; | |
console.log("reset:" + count); | |
} | |
} | |
return new Counter() ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment