I don´t get why "this" in this case returns "NaN" :
function Counter() {
this.num = 0;
this.timer = setInterval(function add() {
this.num++;
console.log(this.num);
}, 1000);
}
And in this one it refers to "this.value":
function foo() {
this.value = 'Hello, world';
this.bar = function() {
alert(this.value);
}
}
var inst = new foo();
inst.bar();
I get that in the first case "this" is pointing to the Window object, I just don´t get why that´s the case.