Using standard es5 I have this method that allows me to add methods to the prototype chain of my library (this allows me to expand the main library, as well as any components that are attached to the library):
library.extend = function(extendId, extendObj) {
if(extendId === 'library') {
library.prototype[extendObj.name] = extendObj.func;
} else {
library.component[extendId].prototype[extendObj.name] = extendObj;
}
};
Using:
var somecomponent = function() {}
somecomponent.protoype.somemethod = function() {}
library.extend('library', somecomponent)
In es6 classes, we also have prototypes, but they are masked by the class syntax, and you must add methods to the class using the method extends.
Because of this, I'm not sure how I can programmatically add methods to es6 classes using a method similar to the one I have above.
source
share