[UPDATE] It turns out that I totally misunderstand scope of closure: The answer is here:
How do JavaScript closures work?
Example 7 answer my question, very helpful.
===================================================================
All:
I wonder how can I make a copy of a closure function like:
function closure(){
var cv = "closure variable";
function changecv(newcv){
cv = newcv;
}
changecv.getcv = function(){return cv;}
return changecv;
}
Say I have another function to duplicate this closure function:
function dupclosure(cFn){..... I do not know how to do this...}
var newclosureFn = dupclosure(closure);
var cf1 = closure();
var cf2 = newclosureFn ();
cf1("new closure variable");
console.log( cf2.getcv() ); // still "closure variable"
Thanks