@Tsukihime You would have to ensure any plugin that changes `Pawn` to be loaded before the plugin that adds `Tank`, as you would have to do the way most plugins are written in MV as well. You could call some prototype methods during runtime, like this, but it adds a whole other can of worms if the methods don't return static values and rely on context and/or instance properties:
Code:
// our base soldier class
class Pawn {
get hp() {
return 100;
}
}
// some special unit with twice the HP
class Tank extends Pawn {
constructor() {
super();
}
get hp() {
return Pawn.prototype.hp * 2; // Calls the prototype method hp of Pawn during runtime, resolving it on each call
}
}
console.log(new Pawn().hp) // 100
console.log(new Tank().hp) // 200. As expected
// NEW PLUGIN that gives all of our units 1000 HP bonus!
Pawn = class extends Pawn {
get hp() {
return super.hp + 1000
}
}
console.log(new Pawn().hp) // 1100. Works well.
console.log(new Tank().hp) // 2200. As expected, as it now points to the current prototype method `hp` of `Pawn` during runtimeThis would of course break if `Pawn` defined hp something like this:
Code:
class Pawn {
constructor() {
this._hp = 100;
}
get hp() {
return this._hp;
}
}We can't call `Pawn.prototype.hp` now because it doesn't have the context object `this` defined, and thus would return undefined.
This problem is one you will always have when you overwrite and extend classes in this manner, and compatibility will always be a challenge no matter which option you opt to go for. I'm curious to see if MZ is using modules (export/import), however; that could change things a lot: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import