
获得徽章 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 才能打印
展开
评论
点赞
赞了这篇文章
赞了这篇文章