Skip to content

Instantly share code, notes, and snippets.

@gregtatum
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save gregtatum/226b6abe4a0328791d18 to your computer and use it in GitHub Desktop.

Select an option

Save gregtatum/226b6abe4a0328791d18 to your computer and use it in GitHub Desktop.
What led me to use automatic semi-colon insertion

What led me to use automatic semi-colon insertion (aside from not having to hit the semi-colon button);

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."
//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
;(function() {
console.log('the only conceptual overhead for automatic semicolon insertion')
})()
//You have to add a semi-colon when starting a line with a ()
// 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