Quote:
Originally Posted by Grue
I guess thats not totally right, there are some times when calling methods inside of other methods where I would need to keep track of this and when its an arrow function and when its not and use .call on occasion but definitely nothing like that interview question which is just bizarre to me.
I was gonna say, I used setInterval(this.foo, 1000) the other day and was a little surprised to find that inside of foo(), 'this' was the global this object, not the object that contained the function foo.
In C++ and java "self" or "this" is (I think) always the object the function is contained in. In python, class functions take a self parameter, but it's auto populated in cases where you invoke a class method like "this.foo() or mything.foo()"
It seems like an odd choice to treat all functions as essentially unbound. Anyway it's not hard to fix, but I was surprised.