Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upcallback && callback(); #52
Comments
|
+1 |
|
This leads to an error in JSLint and a warning in JSHint, "Expected an assignment or function call and instead saw an expression”. As JSLint explains its
The warning is useful and worth enabling as it does catch typos like JSLint explains. The line you wrote, var shouldCallCallback = (Math.random() > 0.5);
shouldCallCallback && callback;JSLint will give the same warning for the code, and this time it caught a typo: var shouldCallCallback = (Math.random() > 0.5);
if (shouldCallCallback) {
callback;
}The second example would likely be more quickly noticed by the developer, but again JSLint/JSHint is able to point it out. I find using an explicit There is nothing "wrong" with writing |
|
I think it is more readable to make an |
|
I make such if's, a one liners: if (callback) callback();Still lint will scream, but I take such approach as much more justified (and readable) than hacky |
|
I added a link to this discussion so folks can come back and read through this and add to the discussion. |
|
I always prefer to use if statements while developing. When the project is built, uglifyjs will short-circuit the if statements to use the construct like yours. |
|
I don't think either one adequately covers safely attempting to run your callback
is what I use to be safe. I don't think a simple null check is a good idea especially when the arguments are variable or when you intend to use arguments[arguments.length - 1] convention:
Otherwise:
|
JoaoFOliveira
mentioned this issue
zhuxiaojian
mentioned this issue
supersky07
mentioned this issue
hshoff
mentioned this issue
mqy1023
mentioned this issue
kangning1206
mentioned this issue
yanlee26
mentioned this issue
Hibop
mentioned this issue
lesonwu
mentioned this issue
|
What about |
|
@yisibl thats equivalent to |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Was reading through the style guide, but couldn't find anything about this. Instead of
I've started using
Which I haven't found any issues with. Would this style guide frown upon this?