In my project, I have various objects that extend other objects from a library. The library object extends the Object class of the library.
Therefore, the architecture is as follows:
// The library object class
class Object {
}
// The library object1 class that extends object library class
class Object1 extends Object{
}
// The library object2 class that extends object library class
class Object2 extends Object{
}
// My object class that extends Object1 library class
class MyObject extends Object1{
}
// My second object class that extends Object2 library class
class MySecondObject extends Object2{
}
My question is, how can I use ES6 syntax to add a method to the 'Object' class of the library I am using without modifying the code of the library (a Node module).
In ES5, I would have done something like:
MyLib.Object.prototype.myNewMethod = function () {
}
In order to achieve:
const o = new MyObject();
o.myNewMethod();
const o2 = new MySecondObject();
o2.myNewMethod();
Thank you for your assistance.