I have an array of objects that holds each "actionButton" id, selector and callback
var actionButtons = [
{
id:"0",
selector:"._55ln._qhr",
callback: undefined
},
{
id:"1",
selector:"._22aq._jhr",
callback: undefined
},
.
.
.
];
What I'm trying to do is calling a function with a specific parameter from the array(the id) every time a selector is clicked.
for(var i=0;i<actionButtons.length;i++){
$(document).on('click', actionButtons[i].selector, function() {
makeAction(actionButtons[i].id);
if (actionButtons[i].callback)
actionButtons[i].callback(this);
});
}
But this code is not working; it looks like every time the callback function is called the value of i
is equal to the array size.
How can I solve this problem;ie. to make the value of the variable i
become different for each callback.