DEV Community

Discussion on: The Fine Art of the Webpack 2 Config

Collapse
 
menssen profile image
Dan Menssen

Nitpick:

Does it seem strange to anyone else that the function needs to be wrapped in () like (functionGoesHere) for the self-executing to work?

In your example, it doesn't, because the context is already an expression.

This works fine:

const x = { y: function() { return 'z' }() }
console.log(x.y) // z
Enter fullscreen mode Exit fullscreen mode

But this doesn't and the parens are required:

function() {
  console.log('a')
}()
Enter fullscreen mode Exit fullscreen mode

Using them in your example is a convention. See also eslint.org/docs/rules/wrap-iife