我想使用从同一个类的方法装饰器传递给类装饰器的信息。这是(虚拟)类的样子:
@classDecorator({
something: 'very interesting'
})
class MyClass{
@methodDecorator({
pure: false
})
someMethod() {
...
}
}
现在,我对使用methodDecorator内部提供给classDecorator({something: very interesting'}
)的参数感兴趣。
我希望我可以使用Reflect API,但无济于事:
function classDecorator(info) {
// classDecorator parameter available here as 'info'
return function(target, propertyKey, descriptor) {
return descriptor
}
}
function methodDecorator(config) {
// propertyDecorator parameter availabe here as 'config'
return function(target, propertyKey, descriptor) {
// I thought I could access the class' decorator params with the reflect api
Reflect.getMetadata('custom:annotation', target)
Reflect.getMetadata('design:type', target)
Reflect.getMetadata('design:paramtypes', target)
// but all of the above are undefined
return descriptor
}
}
是否可以从同一类的methodDecorator中访问classDecorator的参数?