are you talking about a private method?
-
function adder(base){
-
var amt = Number(base);
-
var total = amt;
-
function add(){
-
total += amt;
-
return total;
-
}
-
return add;
-
}
-
-
//test"
-
a= new adder(6)
-
a()//12
-
a()//18
-
a()//24
-
the running total and the increment amount are closed by the inner function.
May be i was wrong ... i could not explain what i wanted to know :-(
I tested this morning to explain you a little bit clear .
My code snippet goes here ...
-
function outer_function()
-
{
-
var a = 10;
-
function inner_function(){
-
a++;
-
alert(a);
-
}
-
return inner_function;
-
}
-
-
function test(){
-
var a = outer_function();
-
for(var i=0;i<10;i++) a();
-
}
-
And i call the test function some how, and what i got that is a single closure is shared by each function call ..means each inner function calls.
But i wanted to know that can it be possible 2 create separate closure for each inner function calls.
I think you are confused to understand ..
let me be clear more ...Yesterday i went through a site ..
go through the 7th example
please make me understand :-)
Kind regards ...