; really required after each method?

I usually see this:

Scene_MiniMap.prototype.initialize = function() { Scene_MenuBase.prototype.initialize.call(this);}; <<< ;But this also works just fine:

Scene_MiniMap.prototype.initialize = function() { Scene_MenuBase.prototype.initialize.call(this);} // <<< removed ;What's the difference? Which one is better and why?
You don't need semi-colons in JavaScript. You could have zero semi-colons in your entire code and it would still work, most parsers will read just fine (I've not tested this on RMMV, but I figure it does too). The issue is that in some specific situations, the parser may interpret that something is part of the same statement when you didn't intend it to be so.

For the sake of consistency and clarity, you do should use semi-colons at the end of every statement, despite the fact that you're not required to do so.

Now, if you're used to method declarations in other languages, you might find it weird to have a semi-color after that. But there's a different in how we're creating methods here.

In some other language, you might have:

public String Foo(){    return "bar";}Those declarations indeed do not have a semi-colon at their end.

But in JavaScript, we're assigning a function to a variable.

Just like this would have a semi-colon:

Scene_MiniMap.prototype.initialize = "foo_bar";So does this:

Scene_MiniMap.prototype.initialize = function();And therefore so does this:

Code:
Scene_MiniMap.prototype.initialize = function() {    Scene_MenuBase.prototype.initialize.call(this);};
Using a semicolon at the end of each statement also helps when trying to 'minify' your code. Cant really be done otherwise! 🙂
What's the difference? Which one is better and why?
A lot depends on the parser or compiler and the exact language used for the code.
Allowing the programmer to forget the ; makes for easier to write code that is also a bit more difficult to parse and read.


Other languages are not as forgiving in those cases, and that is for a good reason - but it can also cause problems if the programmer is sloppy.


There was a NASA mission several decades ago that failed because one of the programmers forgot a single ; in the pascal code used, and that changed how the code was processed...
There was a NASA mission several decades ago that failed because one of the programmers forgot a single ; in the pascal code used, and that changed how the code was processed...
Is that true? Thats an EPIC failure!!! OMG...
Yes, you should add semi-colons.


Javascript compilers will try to do it for you, but they can get it wrong, and the results may be devastating.


I have run into cases where not adding semi-colons caused MV to not parse my script correctly.
There was a NASA mission several decades ago that failed because one of the programmers forgot a single ; in the pascal code used, and that changed how the code was processed...
Wait? NASA uses Javascript to fly rockets? Woah! 
I know it's just a variable asignment in Javascript. But to me it's a method declaration and method declarations imo should not have semi-colons at the end.

Scene_MiniMap.prototype.initialize = function() { Scene_MenuBase.prototype.initialize.call(this); // << this one okay}; // << this one... Feels wrong. But if I leave it out, it could maybe in theory someday be interpreted wrongly...Damnit so I should put them behind every method as well then..
A lot of code languages, such as C/C++ use ; to separate each statement form the next. Its the common separator. 🙂
Is that true? Thats an EPIC failure!!! OMG...
http://priceonomics.com/the-typo-that-destroyed-a-space-shuttle/


A hyphen, not a semicolon though.
Pascal is a different programming language.

Personally, i do it like i've done in Java for a long time, which is adding a ; after every statement except if and while (but after do-while).

I know it's just a variable asignment in Javascript. But to me it's a method declaration and method declarations imo should not have semi-colons at the end.

Code:
Scene_MiniMap.prototype.initialize = function() {    Scene_MenuBase.prototype.initialize.call(this); // << this one okay}; // << this one... Feels wrong. But if I leave it out, it could maybe in theory someday be interpreted wrongly...
Damnit so I should put them behind every method as well then..
It's assigning a variable to an anonymous function, so i would put a ; there. Now, if you would write
Code:
function abc() {}
I wouldn't add a ;
I know it's just a variable asignment in Javascript. But to me it's a method declaration and method declarations imo should not have semi-colons at the end.

Scene_MiniMap.prototype.initialize = function() { Scene_MenuBase.prototype.initialize.call(this); // << this one okay}; // << this one... Feels wrong. But if I leave it out, it could maybe in theory someday be interpreted wrongly...Damnit so I should put them behind every method as well then..
An example of a situation where it could be interpreted differently from what you'd want to:

Scene_MiniMap.prototype.initialize = function() {    Scene_MenuBase.prototype.initialize.call(this);}(function() {    //do some other stuff not related to the above})();If you don't have a semi-colon after that first function declaration, I think the parser will likely interpret the second function as being a parameter to the implicit call of the first function and then the last (); will fail with "is not a function". Certainly not what you wanted.
If something is an expression (you're running code) add a semi-colon. If you are declaring something, don't add it. Anything that uses an optional curly bracket should not have semi-colons either:

Code:
function x(){}x = function() {};if (x) {}while (x){}x();
I know it's just a variable asignment in Javascript. But to me it's a method declaration and method declarations imo should not have semi-colons at the end.

Scene_MiniMap.prototype.initialize = function() { Scene_MenuBase.prototype.initialize.call(this); // << this one okay}; // << this one... Feels wrong. But if I leave it out, it could maybe in theory someday be interpreted wrongly...Damnit so I should put them behind every method as well then..
The semi-colon after your function declaration is indeed for the assignment and has nothing to do with the declaration of the function.

It's like you would do:

function a { // do something }Scene_Minimap.prototype.initialize = a;It's virtually the same just in one single step.

If you don't assign a function to a variable, you don't need the semi-colon after the closing brackets.
I usually see this:

Scene_MiniMap.prototype.initialize = function() { Scene_MenuBase.prototype.initialize.call(this);}; <<< ;But this also works just fine:

Scene_MiniMap.prototype.initialize = function() { Scene_MenuBase.prototype.initialize.call(this);} // <<< removed ;What's the difference? Which one is better and why?
JavaScript has ASI (Automatic Semicolon Insertion), the set of rule where ASI applies are not exactly straightforward for someone that start using JS,

it's possible to avoid semicolon in most cases, basically the rule is that if the parser can understand you intended to break the line there for a reason it inserts the semicolon;

If the new line can continue the previous one then you have a trouble,

mostly this means that if you always use brackets {} you just have to avoid starting a line with a ( or a [ to be safe, for example:

(function(){ // ...})['a','b','c].forEach(function(){ // ...})is probably not what you want as the first function expression is followed by a sequence expression (a sequence of stuff with comma, this means that everything between comma gets executed and the last value is returned), so at some point your JS will look like this for your interpreter:

(function(){})['c'].forEach(function(){})so JS will try to see if function(){} has a 'c' property and if so it will evaluate it, then try to run forEach on the result.

let's suppose you have something like 

Function.prototype.c = [1,2,3];

before that expression this means that JS will manage to execute the forEach but on the 1,2,3 sequence instead of the 'a','b','c' that you would expect

so bottom line, put semicolon where needed, if not sure put semicolon at the end of any line that can end with semicolon until you get the rule better,

however when working in project where semicolon everywhere is agreed just stick to the rule 🙂

EDIT:

this site seems to have the ruleset explained better (and explains the possible pitfalls as well):

http://inimino.org/~inimino/blog/javascript_semicolons
If you're not sure, use jslint and add a semi-colon where it says you should and remove the semi-colon where it says you should 🙂
Using a semicolon at the end of each statement also helps when trying to 'minify' your code. Cant really be done otherwise! 🙂
This is not true anymore, any good minifier nowadays transform your code in an AST and when doing so any not meaningful semicolon is just ignored, this may have been true in the past when people just concat together different files and sometime one ended in an expression and the following started with ( or [, most likely the first as people use to wrap their code in a IIFE.
This is not true anymore, any good minifier nowadays transform your code in an AST and when doing so any not meaningful semicolon is just ignored, this may have been true in the past when people just concat together different files and sometime one ended in an expression and the following started with ( or [, most likely the first as people use to wrap their code in a IIFE.

this ^

How ever I have been reading some articles that leaving out the ; can cause issues, especially if you concat your scripts. though there is no actual proof, just issues on github people have found
Why does nobody put a ; behind the i++? Shouldn't it also have one?

Code:
for(var i=0; i<someArray.length; i++){}
for-loops get special treatment, see here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for

Original thread: https://forums.rpgmakerweb.com/threads/really-required-after-each-method.51137/