Hi I want pass the var antwoord
to
opleidingArray.forEach(haalScoresOp, antwoord);
So I can use it in the function HaalScoresOp
var antwoordenPerVraag = [2,1,3];
function haalScoresOp(item, index) {
console.log("haal score op voor");
console.log(item.naam, item.scores);
console.log("haal antwoord op", antwoord);
}
function berekenEindresultaten(item, index)
{
var opleidingArray = VragenEnScores.vragen[index].opleidingen;
var antwoord = "bla";
opleidingArray.forEach(haalScoresOp, antwoord);
}
antwoordenPerVraag.forEach(berekenEindresultaten);
- I tried binding but this does not function.
- I am getting antwoord is not defined as an error.
opleidingArray.forEach(haalScoresOp, antwoord);
, you're passing in theantwoord
variable as a parameter - this is just astring
, hence your "antwoord is not defined as an error" message. Try removing theantwoord
parameter from theforEach
callantwoord
inhaalScoresOp()
is not in scope, its local toberekenEindresultaten()
var params={antwoord:"bla"};
and then.forEach(haalScoresOp.bind(params))
, and thenthis.antwoord
within the function.