var getValue,setValue;
(function(){
var secret=0;
getValue=function(){
return secret;
};
setValue=function(v){
if(typeof v==="number"){
secret=v;
}
};
}());
getValue();//0
setValue(123);
getValue();//123
setValue(false);
getValue();//123
世界只因有你2017-06-26 10:59:34
getValue()
and setValue()
are closures, sharing a variable secret
, so if the secret
is changed in the setValue
function, getValue()
will of course read the secret
Change accordingly.