constructorTyp为什么可以打印name属性?

来源:8-11 泛型工厂函数类型的真实应用

龙一飞_kiwi

2024-01-28

function createConstructorFactory(constructorTyp:ConstructorInter){
console.log(${constructorTyp.name}'创建了)
return new constructorTyp()
}
createConstructorFactory(CommercialBank)
老师我想问下,这里constructorTyp有name的属性吗?我这里编辑报错说是没有name属性。,CommercialBank的name不是定义的static,所以应该没有name属性。希望老师指点

写回答

1回答

keviny79

2024-01-30

constructorTyp 有双重身份, 当  new constructorTyp() 时  为 constructorTyp  对象的类型,  当 constructorTyp.name 是一个函数对象,name 获取的函数对象空间中的 name 属性。

0
0

TypeScript 从入门到深度掌握,晋级TS高手

200+技术点,22 场景应用,Vue3 源码 TS 用法剖析

430 学习 · 53 问题

查看课程