我有一个有反应和打字记录的项目。
我创建了一个模型来解析来自endPoint的数据。
export class MyClassModel{
constructor(
public name:string,
public url:string,
) {}
get names():string{
return this.name
}
static parsedResponse = ({name,url}:Result):MyClassModel=> {
const model = new MyClassModel(
name,
url
)
return model;
}
}我的模型类有一个静态方法,它返回类的一个新对象,但是当我通过控制台查看响应时,该方法返回一个类型为" object“的对象,而不是类型为"MyClass”的对象。
console.log(new MyClassModel("name","https://www.example.com/"))结果:

这是正常的吗?我使用过Vue3,使用了相同的逻辑,控制台通常显示"MyClass“类型。
发布于 2022-10-22 14:56:05
这是浏览器特有的。例如,如果您这样做:
class X {}
new X();Chrome devtools秀
▼ X {}
▼ [[Prototype]]: Object
► constructor: class X
► [[Prototype]]: Object而firefox devtools显示
▼ Object { }
▼ <prototype>: Object { ... }
► constructor: class X {}
► <prototype>: Object { ... }https://stackoverflow.com/questions/74164361
复制相似问题