Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

Javascript object structure difference

Can you explain me what is the difference between these two objects? How can I add word 'Product' at the beginning of the object?

Array(2)
0: {status: "published", _id: "5ff584e56153e75706790fa9", title: "bbbbb", imageUrl: "images/2021-01-06T11:59:42.006Z-7pIfYwyRCL8.jpg", price: 3333111,?…}

1: Product?{_id: "5ff58d1c6153e75706790faa", title: "5555555", imageUrl: "images/2021-01-06T11:30:26.521Z-7pIfYwyRCL8.jpg", description: "sddsdsd", price: 3333,?…}length: 2

Also, the image: enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thats because this second one was most likely created using

const product = new Product(...)

while first one

const product = {...}

And so the type doesn't match

It's similar to this case

const someMap = new Map();
someMap.set("hello", "world");

const someObject = {
    hello: "world",
}

someMap == someObject // false
someMap === someObject // false

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...