I am making a plugin for Aurelia and need a class decorator which
- adds attributes to an instance of a new object and
- calls an external function with a new object as an argument.
I looked through the examples, and so far I have compiled ("pseudo-ish" code)
return function addAndCall(target: any): any {
var original = target;
var newConstructor = function (...args) {
original.apply(this, args);
this.newAttribute = "object instance value";
ExternalModule.externalFunction(this);
};
newConstructor.prototype = Object.create(original.prototype);
newConstructor.prototype.constructor = original;
return <any>newConstructor;
}
but
- I don’t quite understand the details here (or what really is needed), and
- it may not work properly, as I get Aurelia errors when using objects created from classes with this decorator (and I suspect that this is my decorator, not the Aurelia framework).
Any help and explanation would be greatly appreciated!
source
share