So I did read up a bit on Immediately-Invoked Function Expressions, but I am still not sure I quite comprehend it.
Some plugins seem to put all their code into an IIFE, like this:
Also I seem to have to put some code outside the IIFE, or the game will give me an error, for example if I define a new Scene:
So do I have to declare Scene_Warfare outside the IIFE, or do I just have to change the Syntax if I want to add it inside the IIFE?
Some plugins seem to put all their code into an IIFE, like this:
others just omit this and put in all their code without an IIFE expression.(function() {
// plugin code //
})();
Both seems to work most of the time. As far as I have understood it the reson to use IIFE is to hide variables inside its scope and not make them global on accident, is that correct?// plugin code //
Also I seem to have to put some code outside the IIFE, or the game will give me an error, for example if I define a new Scene:
works, howeverfunction Scene_Warfare() {
this.initialize.apply(this, arguments);
};
Scene_Warfare.prototype = Object.create(Scene_Base.prototype);
Scene_Warfare.prototype.constructor = Scene_Warfare;
...
doesn't and just leads to the error "Scene_Warfare is not defined".(function() {
function Scene_Warfare() {
this.initialize.apply(this, arguments);
};
Scene_Warfare.prototype = Object.create(Scene_Base.prototype);
Scene_Warfare.prototype.constructor = Scene_Warfare;
...
})();
So do I have to declare Scene_Warfare outside the IIFE, or do I just have to change the Syntax if I want to add it inside the IIFE?
