I'm coding a TinyMCE plugin for Wordpress and I've just run in to a little issue with how I'm approaching things. Basically, I'm using a loop which relies on a counter i
. The loop is responsible for building an array with TinyMce details in it. One of those things is a function call which is passed the i
counter.
But of course, by the time that the click actually registers, that counter is always at it's maximum. I solved this temporarily by using let
in my loop. Here's the loop:
for(let i = 0; i <= pmsb.config.length - 1; i++) {
menu[i] = {
text: pmsb.config[i].title,
onclick: function() {
open_dialog(i);
}
}
}
I'm aware that let
isn't well supported and with this being a Wordpress plugin, I've no real control over the browsers which my target audience will use.
So in the case of the above loop - how do I make the function call receive the correct number (as let
does)?