I'm not well versed in JavaScript. I have an object below (Foo.bar) that I want to both feed and print items from a queue every 100 ms.
var Foo = Foo || {};
Foo.bar = {
initialize: function () {
this.feedQueue();
this.consumeQueue();
},
queue: [],
consumeQueue: function () {
if (this.queue > 0) {
var item = this.queue.shift();
console.log(item);
}
setTimeout(function () {
this.consumeQueue();
}, 100);
},
feedQueue: function () {
this.queue.push(Math.random());
setTimeout(function () {
this.feedQueue();
}, 100);
}
};
Foo.bar.initialize();
Within the consumeQueue function "this.queue" never updates. It always is empty.
Can anyone help me out here with what I am doing wrong?
this) issue