我想装饰一个setter函数,一类像这样:打字稿装饰setter函数
export class SearchResultSortBy{
private sortByChoice;
constructor() { ...}
/* getters & setters */
get sortBy() {
return this.sortByChoice;
};
@myDeco({o:'something',o2:'another something'})
set sortBy(sortBy) {
this.sortByChoice = sortBy;
};
}
与装饰:
export function myDeco(element:any){
return (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => {
descriptor.set = function(...args: any[]) {
console.log("The method args are: " + JSON.stringify(args)); // pre
var result = originalMethod.apply(this, args); // run and store the result
someOtherStaticClass.someFunc(element); // post
return result; // return the result of the original method
};
return descriptor;
};
}
但装饰是从来没有所谓的/没有按”不要做任何事情。
如果我放在@myDeco上形成消气功能的顶部,然后装饰被调用,它的工作,这是非常奇怪的......(装饰二传手FUNC。)
是有可能装修setter函数在打字稿?
这确实有效。请你详细说明为什么订单如此重要?为什么我不能装饰两个?这是打字稿成熟度问题吗? – Igoros