Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created August 8, 2015 07:14
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 chuck0523/5402010fa370449ffa52 to your computer and use it in GitHub Desktop.
Save chuck0523/5402010fa370449ffa52 to your computer and use it in GitHub Desktop.
var myObj = {
value : 0,
increment : function(inc) {
this.value += typeof inc === 'number' ? inc : 1;
}
};
// 上記のvalueを保護するとこうなる
var myObj = function() {
var value = 0;
return {
increment : function() {
value += typeof inc === 'number' ? inc : 1;
},
getValue : function() {
return value;
}
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment