Last active
December 11, 2015 21:58
-
-
Save dclowd9901/4666044 to your computer and use it in GitHub Desktop.
IdiomaticJS vs. IdiomaticJS @ Linkedin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hey all, | |
During our meeting, Seth asked me what all the differences were between the vanilla IdiomaticJS standard and the LinkedIn idiomatic JS standard. I didn't feel I gave a very sufficient answer, so I decided to run the diff myself and cull out the JS@LinkedIn agreed-upon changes (plus, frankly, it's something I should just know): | |
1. args in parentheses will not internally wrap spacing: | |
for ( i in bar ) { ... | |
becomes | |
for (i in bar) { ... | |
if ( foo === bar ) { ... | |
becomes | |
if (foo === bar) { ... | |
var fruits = [ 'apples', 'peaches', 'pears' ]; | |
becomes | |
var fruits = ['apples', 'peaches', 'pears']; | |
2. Cleanup in some of the code examples (making styling easier to follow) | |
3. They used double-quotes fairly liberally; we removed them from the doc entirely (as per our style of not using double-quotes, enforced by JSHint): | |
"For consistency, single-quotes (') are preferred as opposed to double-quotes ("). This is helpful when creating strings that include HTML." | |
4. Name booleans in a positive way to avoid the confusing double negative. | |
hasNoWater evaluating to true | |
should be | |
hasWater evaluating to false | |
5. Hungarian Notation (prefixing) are common and encouraged in these situations: | |
Regular expressions: | |
rDesc = /abc/gi; | |
Private or protected: | |
var _privateValue; | |
Cached copy of a jQuery-wrapped object: | |
$mainContainer = $('#main'); | |
6. White-spacing function declarations: | |
function foo(arr1, arr2) {... | |
var foo = function (arr1, arr2) {... | |
(function () { | |
}(inv)); // Note the invocated value is *inside* the parens, though both inside and outside are acceptable by ECMA, JSHint will throw an error when it is invoked outside. | |
7. Use semicolons where applicable (which is pretty much anywhere besides named or anonymous functions): | |
Declarations | |
var foo = 1; | |
var bar = function () { | |
// ... | |
}; | |
function bar() { | |
// ... | |
} | |
Statements & Expressions | |
users.push('Bob'); | |
7. Don't use comma-first: | |
// bad | |
var bar = 1 | |
, foo = 2 | |
, baz = 3; | |
// good | |
var bar = 1, | |
foo = 2, | |
baz = 3; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment