4
我正在爲奧裏利亞一個插件,需要一個類裝飾器打字稿類裝飾修飾對象實例
- 增加屬性到新的對象實例,並
- 調用新對象的外部函數作爲論據。
我已經通過實例看,到目前爲止,我已經把(「僞十歲上下的」代碼)
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框架是越野車)。
任何幫助和解釋將不勝感激!
願望我早就看到了這個 - 花了我數小時纔想出來。 –