Skip to content

Commit

Permalink
fixed style
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Dec 2, 2011
1 parent cec8d36 commit b080a50
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions docs/styleGuide.md
Expand Up @@ -92,7 +92,7 @@ Forked from [idiomatic.js][1]
// 2.B.2.1
// Named Function Declaration
function foo(arg1, argN) {

/* code */
}

// Usage
Expand All @@ -103,7 +103,6 @@ Forked from [idiomatic.js][1]
// Named Function (w/ callback argument)
// callbacks will always be the last argument
function bar(arg1, callback) {

if (arg1 && callback) {
callback();
}
Expand All @@ -121,12 +120,12 @@ Forked from [idiomatic.js][1]
// Function Expression
// Never use non-anonymous function expressions
// Always favour function declarations.
// Only exception is the desire to have a single anonymous function in
// A exception is the desire to have a single anonymous function in
// global scope

(function _yourSingleGlobalAnonymousFunctionClosure () {
/* code */
})
}())

// Another exception is NFE on an object literal

Expand All @@ -139,11 +138,11 @@ Forked from [idiomatic.js][1]
// 2.B.2.4
// Constructor definition
// Don't use them. Use prototypical OO
```

E. End of Lines and Empty Lines

Whitespace can ruin diffs and make changesets impossible to read. Consider incorporating a pre-commit hook that removes end-of-line whitespace and blanks spaces on empty lines automatically.
```

3. <a name="cond">Conditional Evaluation</a>

Expand Down Expand Up @@ -200,11 +199,10 @@ Forked from [idiomatic.js][1]
if (typeof module !== "undefined" && module.exports) {
module.exports = SomeObject;
} else {
global.Object = SomeObject;
global.SomeObject = SomeObject;
}

})(global || window);
}(global || window));


// 4.2.1
Expand Down Expand Up @@ -232,17 +230,18 @@ Forked from [idiomatic.js][1]
if (typeof module !== "undefined" && module.exports) {
module.exports = SomeObject;
} else {
global.Object = SomeObject;
global.SomeObject = SomeObject;
}

})( global || window );
}( global || window ));

```

5. <a name="naming">Naming</a>

Use sensible, readable names

```javascript
// 5.1
// Naming style

Expand Down Expand Up @@ -306,6 +305,22 @@ Forked from [idiomatic.js][1]
// Return statements have a new line after them
// lines of code should be broken up with a new line
// unless they are manipulation the same object
// Don't add a new at the start of a function or the end
// unless it's the global wrapper

// Good:

(function _anonWrapper() {
function name(param) {
var o = param;

o++;

return o;
}

}());

C. inner Function declarations at the bottom

Expand Down

0 comments on commit b080a50

Please sign in to comment.