I have a question which has most likely a simple answer... I'm reading about closures and the like, but don't quite grasp it yet.
ar=[];
r=10;
ar[1]=function (bb) { node.warn ("b:"+bb+"--"+r); }
r=20;
ar[2]=function (cc) { node.warn ("c:"+cc+"--"+r); }
ar[1](2); // output= b:2--20
ar[2](3); // output= c:3--20
I would expect the output if the first to be "b:2--10" and not "b:2--20". So how do I 'fix' this 'r' variable into this function?
I can use two different variables of course (as per suggestion), but this is only an example - I would use this function and call it when needed, each time the same variable will be used, but each time it will have another value.
thanks!