Here is a the simplest function:
module.exports = function Dummy(id) {
this.id = id;
this.delay = function() {
return new Promise(function (resolve, reject) {
// Do some stuff async
// once done
resolve();
});
}
}
I want to instantiate a few instances of this Dummy()
class inside a for loop:
for (var i = 0; i < 3; i++) {
var id = "id_" + i;
var dummy = new Dummy(id);
dummy
.delay()
.then(function () {
console.log(dummy.id);
});
}
However, all of these print id_2
; its as though the instant dummy
is overwritten, even though I am instantiating the variable var dummy
every time inside the for
loop.
Help is appreciated.