0

I've been a googling fool, but I just can't seem to find it. What is it called/named when I call a function with a parameter like this:

(console.log)('test')

For context, I saw it when I started playing around with replacing the process.stdout.write for testing purposes (to make sure log is writing an error message to stdout) along the lines of: Preston Guillory's gist:

process.stdout.write = (function(write) {
    return function(string, encoding, fd) {
        write.apply(process.stdout, arguments)
        callback(string, encoding, fd)
    }
})(process.stdout.write)
rcarver
  • 963
  • 9
  • 13
  • That is an immediately invoked function expression. The parentheses are needed to make sure it is correctly parsed. You would not need it for `(console.log)`, only in function expressions. – trincot Jul 22 '17 at 17:02
  • `(console.log)('test')` doesn't have a name. The important part about the second example is not the first set of parenthesis but the function definition followed by "calling" `()`. – Felix Kling Jul 22 '17 at 17:02
  • Note that what you're actually asking about (at the bottom of your question) is **not** what you have at the top of your question, which is identical to `console.log('test')`. (Unlike the similar-looking but very different `(0, console.log)('test')`.) – T.J. Crowder Jul 22 '17 at 17:03
  • Thank you all :) T.J., I suspected as such that might be the case, thats why I included the whole example. And sorry for the dupes, but I did try and find it :) – rcarver Jul 22 '17 at 17:06

0 Answers0