关于getName参数传递
来源:6-7 装饰器实际使用的小例子

console_man
2020-03-12
老师,请问在调用test.getName()方法时,在装饰器中通过fn()方法执行。
如果test.getName()方法传递了参数,在装饰器中怎么将参数传入fn()执行呢
写回答
2回答
-
Dell
2020-03-15
你用arguments不就可以了嘛
00 -
小蜜蜂15
2020-03-15
这样写也不行...等老师解答吧...
function catchError(msg: string) { return function (target: any, key: string, descriptor: PropertyDescriptor) { const fn = descriptor.value descriptor.value = function () { try { fn(msg) } catch (error) { console.log(msg) } } } } const userInfo: any = undefined class Test { @catchError(msg) // msg报错 getName(msg: string) { return msg } } const test = new Test() test.getName('student')
012021-05-30
相似问题