Skip to content

JS Style Guide: Fix full file closures #106

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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions pages/style-guide/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,47 +249,55 @@ elements
When an entire file is wrapped in a closure, the body of the closure is not indented.

```js
(function( $ ) {
( function( $ ) {

// this doesn't get indented
// This doesn't get indented

})( jQuery );
} )( jQuery );
```

```js
module.exports = function( grunt ) {

// This doesn't get indented

};
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also missing closing backticks, messing up the highlighting of the remaining file...

The same applies to AMD wrappers.

```js
define([
define( [
"foo",
"bar",
"baz"
], function( foo, bar, baz ) {

// this doesn't get indented
// This doesn't get indented

});
} );
```

For UMD, the factory is indented to visually differentiate it from the body.

```js
(function( factory ) {
( function( factory ) {
if ( typeof define === "function" && define.amd ) {

// AMD. Register as an anonymous module.
define([
define( [
"jquery"
], factory );
} else {

// Browser globals
factory( jQuery );
}
}(function( $ ) {
}( function( $ ) {

// this doesn't get indented
// This doesn't get indented

}));
} ) );
```

## Assignments
Expand Down