Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self referential anonymous function #215

Closed
anacrolix opened this issue Aug 1, 2015 · 5 comments

Comments

@anacrolix
Copy link

commented Aug 1, 2015

This kind of code seems quite common:

console.log('meh');
(function a() {
    console.log('hiya');
}());

But standard formats it like so:

console.log('meh');(function a () {
  console.log('hiya')
}())
@pbrinkmeier

This comment has been minimized.

Copy link

commented Aug 2, 2015

It's rather:

console.log('meh')
;(function a () {
  console.log('hiya')
}())

Also, you'll find a couple of reasons not to use this sorrily common pattern.

@anacrolix

This comment has been minimized.

Copy link
Author

commented Aug 2, 2015

Feel free to enlighten me.

@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Aug 2, 2015

Self-calling functions need to be prepended with a ; to prevent it from being interpreted as a call to the returned value from the previous line (e.g. console.log()()).

@pbrinkmeier

This comment has been minimized.

Copy link

commented Aug 3, 2015

What I meant was that you should avoid using IIFEs if you can :)

@feross

This comment has been minimized.

Copy link
Member

commented Aug 4, 2015

Pretty sure that @anacrolix is referring to standard-format. When I run his code through it, it joins the two first lines into one: console.log('meh');(function a () {.

Moved this issue to: maxogden/standard-format#92

@feross feross closed this Aug 4, 2015

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants
You can’t perform that action at this time.