News for hackers. Stuff that matters.
Re:Ways to Invoke a Function in JavaScript by amelius on Sunday June 18, 2017 @04:31PM (#14582745)
At least this one is cheating:

    (_ => console.log(2))();
This is creating a function from which the function (console.log) is invoked. So not a direct call, but two calls instead.
Re:Ways to Invoke a Function in JavaScript by jmull on Sunday June 18, 2017 @04:52PM (#14582860)
A bunch of these are cheating... just wrapping () in various ways or accessing call and apply in various ways. For general functions, I think the commenter who says there are three ways to invoke a function is correct: (), call, apply.

There are additional ways specific functions are called -- I'm thinking of toString and valueOf.

Re:Ways to Invoke a Function in JavaScript by underwater on Sunday June 18, 2017 @07:17PM (#14583543)
Yeah, considering that `Function.prototype.apply === console.log.apply` there are a lot of dupes here. I would consider eval/new Function to be a legitimate fourth way though.
Re:Ways to Invoke a Function in JavaScript by inimino on Sunday June 18, 2017 @09:34PM (#14584055)
Eval is another way to run arbitrary JS code. It's cheating here because nothing about the use of eval is specific to calling a function.

According to that standard, opening an external interpreter would be yet another way.

Agree with the above that there are really only three ways here.

Re:Ways to Invoke a Function in JavaScript by jmull on Sunday June 18, 2017 @08:53PM (#14583883)
Yes, you have a good point about eval and anything else that boils down to invoking a string as a function.
Re:Ways to Invoke a Function in JavaScript by rimunroe on Monday June 19, 2017 @08:11AM (#14586287)
As other people have pointed out in the gist, the syntax for tagged template literals gives an additional way to invoke a function

  foo`abc ${bar} ${baz}`
This will call foo with the arguments

  [["abc ", " ", ""], bar, baz]
Re:Ways to Invoke a Function in JavaScript by owebmaster on Sunday June 18, 2017 @04:38PM (#14582789)
Not cheating, this is an anon function and its call
Re:Ways to Invoke a Function in JavaScript by underwater on Sunday June 18, 2017 @07:18PM (#14583548)
`log` is invoked by the expression `console.log(2)`. That's exactly the same as example 1.
Re:Ways to Invoke a Function in JavaScript by shawnz on Sunday June 18, 2017 @07:07PM (#14583501)
but the inner function is not anonymous, which is the focus of the question.