I have this little snippet (this is inside of an object):
var tout = 0;
self.initialize = function() {
    for (var key in periods) {
        setTimeout(function() {
            self.server.sendData('customData', periods[key], 0);
        }, tout);
        tout = tout + 7000;
    }
}
As you can see, I'm iterating through periods object fields, and I need each key to be visible inside my setTimeout() separately. Currently, that is not possible. I was trying something like this, hoping for a miracle:
self.initialize = function() {
    for (var key in periods) {
        var localkey = key; //here is the change
        setTimeout(function() {
            self.server.sendData('customData', periods[localkey], 0);
        }, tout);
        tout = tout + 7000;
    }
}
But obviously, a miracle did not happen. Does anyone have any idea on how to approach this issue?
 
    