Skip to content

Instantly share code, notes, and snippets.

@cyc115
Created May 1, 2015 20:25
Show Gist options
  • Save cyc115/371b45d0f104c4e6b65a to your computer and use it in GitHub Desktop.
Save cyc115/371b45d0f104c4e6b65a to your computer and use it in GitHub Desktop.
js private memeber variable
//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