Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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