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

Question: how do you handle file-wide IIFEs? #179

Closed
rstacruz opened this issue Jul 1, 2015 · 3 comments

Comments

@rstacruz
Copy link
Member

commented Jul 1, 2015

You'll commonly see this pattern in frontend scripts, especially ones using the umd loader:

;(function () {
  // code here
}());

the semicolons are there to prevent oddities in concatenation with other scripts. you can keep the beginning ;, but not the ending ;.

is there a better workaround other than to resort to // eslint-disable-line?

@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Jul 1, 2015

Maybe it's a silly suggestion, but couldn't the concat script be configured to inject a ; between each file?

@feross

This comment has been minimized.

Copy link
Member

commented Jul 1, 2015

I usually write commonJS and use browserify to make a standalone UMD build when I need it, so this hasn't come up for me.

If you're concerned about your users using a naive concatenation script, I would leave the ; at the end of the file and use // eslint-disable-line like you suggested:

;(function () {
  // code here
}()); // eslint-disable-line

I'll leave this issue open for a while in case others have ideas.

@rstacruz

This comment has been minimized.

Copy link
Member Author

commented Jul 2, 2015

Maybe it's a silly suggestion, but couldn't the concat script be configured to inject a ; between each file?

Most smart concatenators would do something like this, but not all concatenators are smart.

@feross feross added the question label Jul 2, 2015

@feross feross closed this Jul 6, 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.
3 participants
You can’t perform that action at this time.