1

I just can't figure out why this function can be executed rightly?

what's the truth behind this situation, other ways like IIFE?

I occasionally find that when I using webpack to bundle one ts module, as below screenshot shows

enter image description here

demo code

(0, console.log)("hello world!")
// hello world!

function test(a, b) {
   console.log(`a =`, a);
   console.log(`b =`, b);
}

(test)(111, 222)
// a = 111
// b = 222

(0, test)(111, 222)
// a = 111
// b = 222

(1, test)(111, 222)
// a = 111
// b = 222

refs

https://en.wikipedia.org/wiki/Immediately-invoked_function_expression

Heretic Monkey
  • 11,078
  • 7
  • 55
  • 112
xgqfrms
  • 7,269
  • 1
  • 50
  • 53

0 Answers0