What led me to use automatic semi-colon insertion (aside from not having to hit the semi-colon button);
Last active
August 29, 2015 14:16
-
-
Save gregtatum/226b6abe4a0328791d18 to your computer and use it in GitHub Desktop.
What led me to use automatic semi-colon insertion
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
| var foo = bar; | |
| var baz = bee | |
| var blarg = bloog; | |
| // Jshint error! | |
| // Missing semicolon in /js/file/path/source.js | |
| // "Crap, I already closed that file and have switched contexts, let's go back and fix it." |
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
| //How JavaScript works | |
| function foo() {} var bar = "true" | |
| // Valid | |
| var foo = function() {} var bar = "this is an error" | |
| // Invalid | |
| //let's add semi-colons everywhere! | |
| function foo() { | |
| console.log('jshint warns: unnecessary semi-colon'); | |
| }; | |
| var foo = function() { | |
| console.log('jshint likes this'); | |
| }; | |
| // those are both functionally equivalent ways of declaring a function | |
| // one needs a semi-colon, and one doesn't, but I just wanted consistency without caring about the underlying syntax | |
| // jshint reminded me when I screwed it up over and over again |
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
| ;(function() { | |
| console.log('the only conceptual overhead for automatic semicolon insertion') | |
| })() | |
| //You have to add a semi-colon when starting a line with a () |
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
| // When writing functional code, semi-colons get in the way | |
| // This happened to me multiple times a day | |
| // Ok, let's do something | |
| var ids = _.map( collection, function toIds( item ) { | |
| return item.id | |
| }); | |
| saveIds( ids ); | |
| //That's pretty trivial, let's nest it by copying and pasting that code block and save ourselves a variable | |
| saveIds( _.map( collection, function toIds( item ) { | |
| return item.id | |
| }); ); | |
| //ERROR, extra semi-colon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment