i'm creating functions inside a for-loop with a variable parameter. Unfortunately, as soon as the for-loop runs a second time, it updates the variable and updates all parameters of the previously generated functions. How can I parse a "detached" value in this loop, so it doesn't get overwritten by the next loop?
My current code is this:
var self = this;
for (var i = 0; i < wordObjects.length; i++) {
var wordCurrent = wordObjects[i].word;
var wordCorrect = wordObjects[i].correct;
var moreData = wordObjects[i].moredata;
var successFunction = wordObjects[i].successFunction;
//chain all arguments in one array
variableArray = []
variableArray = variableArray.concat(wordCorrect);
variableArray = variableArray.concat(moreData);
//create function
var runFunction = function() {self.executeFunctionByName(successFunction, self, variableArray)};
this.saveFunctions[wordCurrent] = runFunction;
};
I tried to generate an object with all arrays inside, but then it didn't pass the arrays at all. It looked like this:
var runFunction = function() {self.executeFunctionByName(successFunction, self, variableArray[i])};
I tried to pass variableArray.slice(); but this didn't seem to work either.
variableArrayis global