【发布时间】:2016-12-30 14:36:28
【问题描述】:
我正在为 Aurelia 制作一个插件,并且需要一个类装饰器
- 为新对象实例添加属性,并且
- 以新对象作为参数调用外部函数。
我浏览了示例,到目前为止我已经整理了(“伪”代码)
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;
}
但是
- 我不完全清楚这里的细节(或实际需要什么),并且
- 它可能无法正常工作,因为我在使用从具有此装饰器的类实例化的对象时遇到 Aurelia 错误(我怀疑它是我的装饰器,而不是有问题的 Aurelia 框架)。
任何帮助和解释将不胜感激!
【问题讨论】:
标签: class typescript decorator aurelia instances