Weird Unexpected token with newlines

This does not work

MM_POI.prototype.makeSaveContents = function(){    return    {        id        :this.id,        name      :this.name // <<< SyntaxError: Unexpected token :    };};This does:

MM_POI.prototype.makeSaveContents = function(){ return { id :this.id, name :this.name };};The only difference is 1 line vs several lines. No difference in code. I even kept the spaces intact. Why is this?
Are you sure the object is built correctly in the example that works? If it does, my guess is that it's because you don't have the opening { on the same line as 'return'.

Also, why do you have the colons all the way over to the values? Typically you leave them with the ID.
Are you sure the object is built correctly in the example that works? If it does, my guess is that it's because you don't have the opening { on the same line as 'return'.

Also, why do you have the colons all the way over to the values? Typically you leave them with the ID.
That is exactly what the problem is, and the problem with JavaScript automatically adding semicolons implicitly.

In any other languages, you have to add semicolons to define the end of a line. In JavaScript, oftentimes it adds those semicolons itself. This means that in other languages you can easily multiline things, while in JavaScript you have to be very careful with that.
Are you sure the object is built correctly in the example that works?
100%. Tested it several times, checked all values.

The colons are so far over because there used to be many more values. But I removed them to find out what was wrong. I thought I had some spelling mistake or a lower/uppercase bug. But nope it was the newline.

So basically, multi-lining in Javascript is also very dangerous? Pfff... Wish we could use c++/c# or something decent. Ruby wasn't great but Javascript really has me baffled so now and then. Strict languages are the best. Just the amount of times I had to debug something only to find out I had an undefined value or used an unexisting variable-name or forgot an uppercase character, but Javascript is okay with all that...

Okay I'll stick to single-line returns then 🙁 . I'll just make a very very very long single-line-return... <insert very disappointing emoticon here>
MM_POI.prototype.makeSaveContents = function(){ return { id: this.id, name: this.name };};thats why

Original thread: https://forums.rpgmakerweb.com/threads/weird-unexpected-token-with-newlines.51248/