PLaying with closure
Trying out some things with closure in JS. FUN
by mich
JavaScript
//playing with closure
var Obj = function ( ) {
var myValue = 0;
return {
increment: function(inc) {
myValue += (typeof inc === 'number') ? inc : 1;
},
getValue: function( ) {
return myValue;
}
}
};
var hello = Obj();
hello.increment(5);
alert(hello.getValue());
alert(hello.myValue);