I use newman library method run which creates EventEmitter. I do in loop and create multiple instances of EventEmitter. When event is fired, I would like to access variable from outer scope and have value which was set at time when method run was invoked (and EventEmitter created).
Pseudo code
for(i = 0; i < n; i++) {
newman.run({
...
})
.on('request', (error, data) => {
console.log(`i=${i}`);
});
This implementation will display value of i from outer scope at the time when event is fired. I want to use value of i at the time when object was created. I tried to use bind()
and got error that object does not have bind method. I tried to created dynamic property and got undefined
.
How to get value of variable from outer scope at time when object was instantiated?