Reputation: 11
compClasses: function() {
/* IT DOES NOT WORK LIKE THIS */
return
{
major: this.valA,
minor: this.valB
}
/* BUT WORKS LIKE THIS KINDLY TAKE NOTICE OF THE PLACEMENT OF CURLY BRACKETS */
return {
major: this.valA,
minor: this.valB
}
}
Upvotes: 1
Views: 74
Reputation: 16079
JavaScript automatically inserts semicolons (or ends statements) when needed. If you write
return
{
major: this.valA,
minor: this.valB
}
the return statement is executed directly (like if you'd write return;
). If you write
return {
major: this.valA,
minor: this.valB
}
the complete object is returned instead. The semicolon is added after the object.
The rules for automatic insertions of semicolons are as followed (source):
}
, closing the current blockreturn
statement on its own linebreak
statement on its own linethrow
statement on its own linecontinue
statement on its own lineUpvotes: 2