i am a bit obscure situation. mainly because i thought i already grasp closures. so basically what i want is to reset to default values a collection. so let say i have collection which has constructor with array of objects parameter.
var c = new collection([{x},{y},{z}]);
then collection periodically get updated.since i am not keeping somewhere initial values of array, after sometime i would like to reset to initial values.
now i am not asking how to implement this, there could be multiple ways my question about closures itself. please read further
so the way i might thought to trap this initial value using closures so it might look like this.
c.on('reset',(function(arr){
return function(){
c.internalarray = arr;
}
})(c.internalarray))
so it is not working seems because the reference is passed as argument the collection updates the suppossedly trapped arr also get updated its end up always true for
arr === c.internalarray;
i might thought to pass the clone of array but what is the point is not that somewhere just creating a copy of data with assigning keeping global variable.
so my question what i am doing wrong. i thought that somehow implicitly javascript engine creates a copy of trapped variable/object. that i dont have to keep track of them.