>This line "(a.c || [])()" is bothering me -- why on earth would this line exist in any program?
A variation of it is valid for method selection, such as:
(cond ? a.foo : b.bar)();
or, for method fallback: (a.foo || a.fooDefault)();
Neither does work in js, though.
Re:Javascript Fundamentals: ‘this’ keyword
by anonytrary on Tuesday August 28, 2018 @03:52AM
(#17857216)
This is useful and works with functions that don't use `this` (like arrow functions).
Re:Javascript Fundamentals: ‘this’ keyword
by pitaj on Saturday August 25, 2018 @05:41PM
(#17842719)
`(a.c)()` is not undefined, it's 42
Re:Javascript Fundamentals: ‘this’ keyword
by anonytrary on Sunday August 26, 2018 @01:06AM
(#17844372)
Nice catch, I should edit that but it's too late. I think my point still stands, however...
I spent about 5 minutes wondering why each line returned 1, 2 and 3 respectively, when they should be returning the global value of b. If you are going to be showing obscure, tricky examples of Javascript, the last thing you want to do is have superfluous comments in your code. Follow comment conventions for the sake of your readers' sanity. This would have been much less confusing: