MV I can't add a function to a class?

Please help me out. It is not letting me add a function to a class. Here is my code:

Spoiler: Code
Sprite_Icon.prototype.testing = function () {} Sprite_Icon.prototype.MyDrawIcon = function (iconIndex, x, y) { var bitmap = ImageManager.loadSystem('IconSet'); var pw = Window_Base._iconWidth; var ph = Window_Base._iconHeight; var sx = iconIndex % 16 * pw; var sy = Math.floor(iconIndex / 16) * ph; this.contents.bitmap.blt(bitmap, sx, sy, pw, ph, x + addPosX, y + addPosY); }; function Sprite_Icon() { this.initialize.apply(this, arguments); } Sprite_Icon.prototype = Object.create(Sprite_Base.prototype); Sprite_Icon.prototype.constructor = Sprite_Icon; Sprite_Icon.prototype.initialize = function (x2, y2) { x = x2; y = y2; width = 16; height = 16; Sprite_Base.prototype.initialize.call(this); }

This is my error:

rpg_managers.js:1949 TypeError: Sprite_Icon.testing is not a function
at Function.BattleManager.startBattle (MyWeaknessPlugin.js:27)
at Scene_Battle.start (rpg_scenes.js:2247)
at Function.SceneManager.updateScene (rpg_managers.js:2019)
at Function.SceneManager.updateMain (rpg_managers.js:1983)
at Function.SceneManager.update (rpg_managers.js:1907)
The error occurs because you are trying to access a property that has not even been created (Sprite_Icon).
Just place the function below the initialization part of the class.

JavaScript:
function Sprite_Icon() {
    this.initialize.apply(this, arguments);
}
Sprite_Icon.prototype = Object.create(Sprite_Base.prototype);
Sprite_Icon.prototype.constructor = Sprite_Icon;
(() => {
    Sprite_Icon.prototype.initialize = function (x2, y2) {
        x = x2;
        y = y2;
        width = 16;
        height = 16;
        Sprite_Base.prototype.initialize.call(this);
    }

    Sprite_Icon.prototype.testing = function () {

    }

    Sprite_Icon.prototype.MyDrawIcon = function (iconIndex, x, y) {
        var bitmap = ImageManager.loadSystem('IconSet');
        var pw = Window_Base._iconWidth;
        var ph = Window_Base._iconHeight;
        var sx = iconIndex % 16 * pw;
        var sy = Math.floor(iconIndex / 16) * ph;
        this.contents.bitmap.blt(bitmap, sx, sy, pw, ph, x + addPosX, y + addPosY);
    };
})();
The error occurs because you are trying to access a property that has not even been created (Sprite_Icon).
Just place the function below the initialization part of the class.

JavaScript:
function Sprite_Icon() {
    this.initialize.apply(this, arguments);
}
Sprite_Icon.prototype = Object.create(Sprite_Base.prototype);
Sprite_Icon.prototype.constructor = Sprite_Icon;
(() => {
    Sprite_Icon.prototype.initialize = function (x2, y2) {
        x = x2;
        y = y2;
        width = 16;
        height = 16;
        Sprite_Base.prototype.initialize.call(this);
    }

    Sprite_Icon.prototype.testing = function () {

    }

    Sprite_Icon.prototype.MyDrawIcon = function (iconIndex, x, y) {
        var bitmap = ImageManager.loadSystem('IconSet');
        var pw = Window_Base._iconWidth;
        var ph = Window_Base._iconHeight;
        var sx = iconIndex % 16 * pw;
        var sy = Math.floor(iconIndex / 16) * ph;
        this.contents.bitmap.blt(bitmap, sx, sy, pw, ph, x + addPosX, y + addPosY);
    };
})();

I went through your code and... what exactly are you trying to do in the initialization function?

Edit:
I just wanted to edit the previous message but ended up posting a new message. lol
Sorry for the disaster.
Hey! That was helpful. Please help me out more:

I am trying to create a weakness plugin. I want to draw an icon representing an elemental weakness for each enemy. After I draw it, I draw the next one next to it. So I iterate through a list of troops and check if they have a weakness/elemental rate above 100% of that element. Then, I create a Sprite_Icon object and in the initialize part I try to move. In the arguments I add x to the x2 argument. But it just doesn't work. The icon is always drawn at the same place, somewhere in the middle of the screen.
Anyone?
I honestly don't understand exactly what you want, but you can try this:

JavaScript:
function Sprite_Icon() {
    this.initialize.apply(this, arguments);
}
Sprite_Icon.prototype = Object.create(Sprite_Base.prototype);
Sprite_Icon.prototype.constructor = Sprite_Icon;
(() => {
    Sprite_Icon.prototype.initialize = function (x, y, iconIndex) {
        Sprite_Base.prototype.initialize.call(this);
        this.position.set(x, y);
        this.setIcon(iconIndex);
    }
    
    Sprite_Icon.prototype.setIcon = function (iconIndex) {
        var bitmap = ImageManager.loadSystem('IconSet');
        var pw = Window_Base._iconWidth;
        var ph = Window_Base._iconHeight;
        var sx = iconIndex % 16 * pw;
        var sy = Math.floor(iconIndex / 16) * ph;
        this.setFrame(sx, sy, pw, ph);
    };
})();
That code still doesn't work. I am trying to do like Olivia's weaknesses. I want the enemies to display the element they are weak against.
@A_Higher_Plane, I would respectfully propose considering in your plugin using the actual Class syntax to declare classes if you are not doing so already.

Here is the syntax:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

There are just too many benefits of using the actual Class syntax to list and to ignore.
@Sepheyer no I think that for this framework you have to create a class like this framework.

Guys please help me out here!!

Original thread: https://forums.rpgmakerweb.com/threads/i-cant-add-a-function-to-a-class.140397/