I am trying to build up a super primitive cue function. Essentially need to repeat an operation n number of times.
var serialCue = {
init:function(length_of_cue, handler){
this.length_of_cue = length_of_cue;
this.handler = handler;
//this.handler();
var index = 0;
},
monitor: function(){
console.log(this.index);
// this.handler();
// this.index++;
// if(this.index>=this.length_of_cue){
// this.handler();
// }
},
eachIteration: function(callback){
console.log("yo");
callback();
},
startProcessing: function(){
for(var count=0;count<this.length_of_cue;count++){
this.eachIteration(this.monitor);
}
}
}
module.exports = Object.create(serialCue);
//IN APP.JS
var cue = require('./serial_cue.js');
cue.init(5,function(){
console.log("done done and done!");
});
cue.startProcessing();
The output returns "undefined" for the value of the index. I am trying to figure why "this" behaves predictably within all of the methods defined for this object except monitor. Still a little shaky with scopes in JS.