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 属性。
00
相似问题
interface同名的问题
回答 1
关于访问对象属性的问题
回答 1