1
是否有通过装饰添加功能的有效方法?通过装饰添加功能
装饰:
function testDecorator(options){
return function(target){
target.test = function() {
console.log('Zipp Zapp!');
};
}
}
类别:
@testDecorator({})
class Book{
}
使用(在这种情况下优选的),如在
Book.test()
打字稿编译结果:
Property 'test' does not exist on type 'typeof Book'.
使用像
var b = new Book();
b.test();
打字稿编译结果:
Property 'test' does not exist on type 'Book'