Sample code:
var functions = {
testFunction: function(){
console.log('test');
}
};
var functionsClones = [];
for(i in [1,2,3]){
var functionsClone = $.extend({}, functions);
functionsClone.testFunction.i = i;
functionsClones.push(functionsClone);
}
$.extend is jQuery function which allows to clone object instead of reffering to it.
Now let's print set properties:
$.each(functionsClones, function(key, functionsClone){
console.log(functionsClone.testFunction.i);
});
It outputs 3 times '2' instead of 0, 1, 2. What's wrong with this code?