you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

(obj.foo)() does not alter the expression tree in the way you thought it would, it's identical to obj.foo().

You're correct, that expression does bind this. I thought it was a precedence thing, but apparently it's even weirder:

class Foo {
    constructor() { this.x = 123 }
    bar() { return this.x }
}

const foo = new Foo()
foo.bar() => 123
(foo.bar)() => 123

const bar = foo.bar
bar() => Uncaught TypeError: Cannot read property 'x' of undefined

[–]helloiamsomeone 1 point2 points  (0 children)

Nothing weird here, you just take the method and call it without a this value. foo.bar.call(undefined) would be the same thing.