Understanding the concept of closure in deep
Hey check this code here,
function getspinner(){
var count = 0;
function increament(){
return ++count;
}
function decreament(){
return --count;
}
return {
up:increament,
down:decreament
}
}
If I call him
var spinner = getspinner();
spinner.up(); // value increments by 1 each time
spinner.down(); // value decrements by 1 each time
But when I call it Like
getspinner().up(); // i'l get 1 each time
getspinner().down(); // i'l get -1 each time
I would like to know the difference. why doesn't the lifetime of the account increase in the case of getspinner (). up () or getspinner (). down ();
+3
source to share
No one has answered this question yet
Check out similar questions: