MZ Constructor throws an undefined error on Window_Base

I'm a newbie on RPG Maker and after I bought MZ, I tried to convert a simple code that displays a Window_Base upon pressing G button from es5 to es6 using a tutorial here. However, adding a constructor to my class that extends Window_Base like in the turorial throws an unidentified 'x' error.

Here's my working code:
JavaScript:
Input.keyMapper["71"] = "openGambitMenu";


_alias_scene_map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function()
{
    _alias_scene_map_update.call(this);
    if(Input.isTriggered("openGambitMenu")) SceneManager.push(SceneGambit);
}




class WindowGambit extends Window_Base
{
    
}



class SceneGambit extends Scene_MenuBase
{
    create()
    {
        super.create();
        var rect = new Rectangle(100, 200, 500, 300);
        this._customWindow = new WindowGambit(rect);
        this._customWindow.drawText("First Box", 0, 0);
        this.addWindow(this._customWindow);
    }
}


SceneGambit.prototype.update = function()
{
    Scene_MenuBase.prototype.update.call(this);
    if(Input.isTriggered("cancel")) SceneManager.pop();
}

The above code actually works. But upon adding this code to WindowGambit
Code:
constructor(){
    super();
}
It throws the error. Am I doing something wrong? What does a constructor actually do? It seems like SceneGambit still works with or without a constructor. Thanks for helping me!
A constructor is the method used to create a new instance of an object:
An ES5 equivalent:
JavaScript:
// define constructor
window.WindowGambit = function() { /* run this code on new instance */ };
// inherit from Window_Base
window.WindowGambit.prototype = Object.create(Window_Base);
// replace inherited constructor with the one just defined
window.WindowGambit.prototype.constructor = WindowGambit;
I imagine the problem is that the Window_Base constructor (redirected to its initialize method) expects a Rectangle argument to determine its position and size, so you should instead do something like this:
JavaScript:
class WindowGambit extends Window_Base {
  constructor(rect) {
    super(rect);
  }
}
If there is a constructor present in the subclass, it needs to first call super() before using "this".
Note that the ES6 class stuff is just alternative syntax for JavaScript's prototype structure; you don't have to use it if you find it confusing. 👋

If you want more help, please quote the full error message you're seeing, word-for-word. E.g. in this case I imagine it is "Uncaught Error: Argument must be a Rectangle". More details (i.e. a traceback) should be available via the dev console: press F8 (or F12 if the game crashed on boot) to show the dev tools window, and select the Console tab. Errors are displayed there in red text, and can be
A constructor is the method used to create a new instance of an object:
An ES5 equivalent:
JavaScript:
// define constructor
window.WindowGambit = function() { /* run this code on new instance */ };
// inherit from Window_Base
window.WindowGambit.prototype = Object.create(Window_Base);
// replace inherited constructor with the one just defined
window.WindowGambit.prototype.constructor = WindowGambit;
I imagine the problem is that the Window_Base constructor (redirected to its initialize method) expects a Rectangle argument to determine its position and size, so you should instead do something like this:
JavaScript:
class WindowGambit extends Window_Base {
  constructor(rect) {
    super(rect);
  }
}
​
Note that the ES6 class stuff is just alternative syntax for JavaScript's prototype structure; you don't have to use it if you find it confusing. 👋

If you want more help, please quote the full error message you're seeing, word-for-word. E.g. in this case I imagine it is "Uncaught Error: Argument must be a Rectangle". More details (i.e. a traceback) should be available via the dev console: press F8 (or F12 if the game crashed on boot) to show the dev tools window, and select the Console tab. Errors are displayed there in red text, and can be
Thanks! It's working now.
Great!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/constructor-throws-an-undefined-error-on-window_base.145749/