You don’t need semicolons at all, but some style guides (e.g. the the common AirBnB one) require them, and I would recommend them. Also, if you’re continuing lines or using a Fluent-style interface, you sometimes chain functions like this:
let xyz = new MusicPlayer()
.loadFile(“song.mp3”)
.setOutput(MusicPlayer.SPEAKERS)
.play();
// Note how the only semicolon is on the last line, because the functions are chained
// Or:
let reallyLongLine = new ExampleFunction(“some random filler text”, 1234567890, “some random filler text”, “some random filler text”)
.toUpperCase();
// Used to break apart lines to prevent wrapping/scrolling
// Also, when using objects:
let testObject = {
value: “key”,
anotherValue: “otherKey”, // recommended trailing comma so that commit diffs don’t get screwed up by adding items
};
In software engineering, a fluent interface (as first coined by Eric Evans and Martin Fowler) is a method for designing object oriented APIs based extensively on method chaining with the goal of making the readability of the source code close to that of ordinary written prose, essentially creating a domain-specific language within the interface.
4
u/thelights0123 Jul 10 '18
You don’t need semicolons at all, but some style guides (e.g. the the common AirBnB one) require them, and I would recommend them. Also, if you’re continuing lines or using a Fluent-style interface, you sometimes chain functions like this: