Created
August 8, 2015 07:14
-
-
Save chuck0523/5402010fa370449ffa52 to your computer and use it in GitHub Desktop.
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
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