Skip to content

Switched modules to bang-style.#7

Merged
hshoff merged 1 commit into
masterfrom
bang_modules
Nov 2, 2012
Merged

Switched modules to bang-style.#7
hshoff merged 1 commit into
masterfrom
bang_modules

Conversation

@reissbaker
Copy link
Copy Markdown
Contributor

I propose writing modules like this:

!function() {
}();

This saves us from a problem that has bitten us in the past, where the following modules work in dev:

// Module A
(function() {
}())
// Module B
(function() {
}());

But blow up in production when the two files get concatenated (note the missing semicolon in Module A). Starting modules with bang (lol) is the shortest possible way to prevent this; ASI will kick in because of the bang and prevent the module from being incorrectly interpreted as arguments to a function call.

@romanfuchs
Copy link
Copy Markdown
Contributor

👍
Used to be more familiar with the second pattern, but I'm all for safer code.

@hshoff
Copy link
Copy Markdown
Member

hshoff commented Nov 2, 2012

Makes sense.

hshoff added a commit that referenced this pull request Nov 2, 2012
Switched modules to bang-style.
@hshoff hshoff merged commit d5a05ef into master Nov 2, 2012
@ajacksified
Copy link
Copy Markdown
Contributor

👍 Same; I'm converting to bang-style.

@hshoff hshoff deleted the bang_modules branch August 8, 2014 06:43
mattgperry pushed a commit to drivetribe/javascript that referenced this pull request Aug 22, 2017
WithSoull added a commit to WithSoull/js-for-trpp that referenced this pull request Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants