【发布时间】:2016-07-05 09:47:56
【问题描述】:
有没有通过装饰器添加功能的有效方法?
装饰者:
function testDecorator(options){
return function(target){
target.test = function() {
console.log('Zipp Zapp!');
};
}
}
类:
@testDecorator({})
class Book{
}
用法(在这种情况下是首选)喜欢
Book.test()
typescript 编译结果:
Property 'test' does not exist on type 'typeof Book'.
用法
var b = new Book();
b.test();
typescript 编译结果:
Property 'test' does not exist on type 'Book'
【问题讨论】:
标签: javascript typescript decorator