This is correct? (SOLVED)

This is the same thing?

1 - Eli.Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;

2 - var _Eli_Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
Almost the same, yes. ^_^
This is the same thing?

1 - Eli.Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
This defines a new property on a variable named "Eli" (or redefines it if it already exists) and sets it to Window_Options.prototype.makeCommandList (method reference).
2 - var _Eli_Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
This defines a new, independent variable on the {enclosing block} (e.g. an IIFE) and sets it to Window_Options.prototype.makeCommandList.

The main difference is scope: putting everything as a property of your own global "Eli" variable (a.k.a. "namespace") means they're accessible outside of the plugin (e.g. by script calls or add-on plugins) but less likely be overwritten by accident. Defining function aliases as variables is perfectly OK though: those usually don't need to be referenced outside of the plugin itself, and if you scope them to your plugin that means other plugins can't access them. Typical usage for both cases:
Spoiler
  • Namespace:
    Code:
    var Eli = Eli || {};  // global variable, set to current value if it exists or an empty object otherwise
    Eli.Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;  // property of global object
    
    (function() {  // IIFE not required here but doesn't affect how things work
      Window_Options.prototype.makeCommandList = function() {
        Eli.Window_Options_makeCommandList.call(this);  // callback via namespace
      };
    })();
  • Local variable:
    Code:
    (function() {  // IIFE for scope: variables defined inside the IIFE are not accessible outside it.
      var _Eli_Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
      Window_Options.prototype.makeCommandList = function() {
        _Eli_Window_Options_makeCommandList.call(this);  // callback via local variable
      };
    })();
Here's the MDN article on scope in case you're interested: https://developer.mozilla.org/en-US/docs/Glossary/Scope
@caethyril
Thank you so much! I'll read it right now!
@Eliaquim when your query is fully resolved please Report your post and ask for it to be closed. Mods might not see a post or change of title but they will see a Report.

Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/this-is-correct-solved.106753/