News for hackers. Stuff that matters.
Re:‘This’ in JavaScript by Cakez0r on Thursday August 03, 2017 @10:18AM (#14919773)
What about setTimeout(obj.method, 1)?

(Spoilers: this == window, not what is left of the function call)

Re:‘This’ in JavaScript by nhpatt on Thursday August 03, 2017 @11:13AM (#14920267)
You are not calling the function, you are passing a reference to setTimeout that calls it directly, without the obj. before the call.

@getify explains it flawlessly, there are 4 modes: new, obj., bind/apply/call and default (window or error in strict mode)

Re:‘This’ in JavaScript by eiriklv on Thursday August 03, 2017 @11:46AM (#14920557)
As nhpatt notes you're not actually calling obj.method here, you're passing it as an argument, which will be called at a later time.

Looking at a possible implementation of setTimeout makes it clearer:

  function setTimeout(func, delay) {
    // wait for the delay to complete..
    func();
  }
Here you can see that when the function is called there's nothing to the left of it.
Re:‘This’ in JavaScript by Cakez0r on Thursday August 03, 2017 @12:25PM (#14920985)
Yup, I get it. I was just pointing out that there are some edge cases to the "context is whatever is left of the function" rule-of-thumb.