获得徽章 12
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
import 'reflect-metadata';
function showData(target: typeof User){
for(let key in target.prototype){
console.log(key)
const data = Reflect.getMetadata('data', target.prototype, key);
console.log(data);
}
}
@showData
class User {
name = 'John';
@Reflect.metadata('data', 'name')
getName() {}
@Reflect.metadata('data', 'age')
getAge() {}
}
这段代码使用 ts-node 执行 为什么不打印 把 tsconfig.json 配置中 "target" 改成 es5 才能打印
function showData(target: typeof User){
for(let key in target.prototype){
console.log(key)
const data = Reflect.getMetadata('data', target.prototype, key);
console.log(data);
}
}
@showData
class User {
name = 'John';
@Reflect.metadata('data', 'name')
getName() {}
@Reflect.metadata('data', 'age')
getAge() {}
}
这段代码使用 ts-node 执行 为什么不打印 把 tsconfig.json 配置中 "target" 改成 es5 才能打印
展开
评论
点赞
,测试说个 bug 别的前端懂业务,说两句就行,我需要从头到尾演示一下![[不失礼貌的微笑]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_16.9d17f6d.png)