News for hackers. Stuff that matters.
Re:Ways to Invoke a Function in JavaScript by fred256 on Sunday June 18, 2017 @04:30PM (#14582738)
Number 2 is cheating IMHO: it is invoking console.log just like 1, just wrapped in an immediately invoked closure. You can keep playing this game ad infinitum:

    (_ => (_ => console.log("2a"))()()
    (_ => (_ => (_ => console.log("2b"))))()()()
Re:Ways to Invoke a Function in JavaScript by Stratoscope on Sunday June 18, 2017 @05:41PM (#14583111)
Exactly. And if anything is notable about #2, then these must be notable too:

  ( function() { console.log("2f") } )()

  ~function() { console.log("2f") }()
Re:Ways to Invoke a Function in JavaScript by kmill on Sunday June 18, 2017 @04:34PM (#14582765)
I wasn't reading carefully, and I thought they mentioned it because it's slightly different from

    (function () { console.log("#"); })();
though not actually since the this is not being used.

I was expecting to see

    console.log.bind(console)("#")
as well.

Edit: bind is farther down in the comments.

Re:Ways to Invoke a Function in JavaScript by jmull on Sunday June 18, 2017 @04:55PM (#14582880)
bind is a way to create a function, not invoke one. Here you're invoking the function (that bind returned) in the normal way, using parenthesis.
Re:Ways to Invoke a Function in JavaScript by kmill on Sunday June 18, 2017 @05:25PM (#14583038)
The list seems to be about different ways a particular function could be called, rather than just the syntax of invocation. Imagine you are making a code analysis program and you want to find all the places console.log is called; I imagined the bind example as encompassing things like

    var log = console.log.bind(console);
    // ... ... ...
    log("#");
Re:Ways to Invoke a Function in JavaScript by jmull on Sunday June 18, 2017 @09:11PM (#14583963)
Ok: static analysis of a language where most fundamental relationships are resolved at runtime.

I guess this is one way to express the futility.

The lesson learned is hook console.log -- or whatever function you are interested in -- meaning, replace it with something that captures the context in which it is called and passes through the call to the original)