I got a bit confused about a code snippet that I took from the react.js docs: http://facebook.github.io/react/docs/reusable-components.html
But I converted it to a general js case:
var SomeFunc = function(){
this.intervals = [];
this.setInterval = function(){
this.intervals.push(setInterval.apply(null, arguments));
};
var self = this;
this.cleanup = setTimeout(function(){
self.intervals.map(clearInterval);
}, 3000);
}
var someFunc = new someFunc();
someFunc.setInterval(this.tick, 1000);
someFunc.cleanup();
I'm confused by the following line:
this.intervals.push(setInterval.apply(null, arguments));
When I console.log the the argument of push, it returns 1.
Can someone explain what actually gets stored in this array?
The cleanup works, so why does the array show the array index number (+1?) instead of what is actually stored in the array?
React.js jsfiddle:
http://jsfiddle.net/xsjfq5ex/2/