javascript - Why is there no real empty object in js?
世界只因有你2017-05-19 10:24:47
0
4
467
In js, use the object literal method to create an object, var obj={}; Since the Object constructor is not called, why is it still an instance? Shouldn't such an object be an empty object? Why is its prototype Object.prototype?
I think you should first tell me what you define as空对象.
According to your title description, I guess what you mean by空对象应该是指最原始的那个对象原型吧?这个东西是有的,它是nullshould refer to the original object prototype, right? This thing exists, it isnull, and it is the end of the prototype chain of all objects.
Conceptually speaking, Object is defined as the root object of all objects and is the most basic unit (reference) of the concept of "object-oriented". If it is removed, the entire concept will collapse; Can you imagine matter without molecules/atoms?
No matter you create it with new or use literals, the compiler will automatically recognize the ancestor of the object
Yeah, null exception, this thing itself is a special case. js treats it as an object at the beginning, and then the so-called "empty object" phenomenon will appear in the subsequent Object.create(null). If it is defined at the beginning is a special value, then there is no such thing as Object.create(null). So in my understanding, this "empty object" is self-consistent and connected in definition, and should not be classified as "object-oriented" In this concept.
var obj = {}; is just a shorthand, equivalent to var obj = Object.create({});
Object.create(null); may be an empty object.
You have to ask about this
Brendan Eich
.I think you should first tell me what you define as
空对象
.According to your title description, I guess what you mean by
空对象
应该是指最原始的那个对象原型吧?这个东西是有的,它是null
should refer to the original object prototype, right? This thing exists, it isnull
, and it is the end of the prototype chain of all objects.js has empty objects
Practice is the only criterion for verifying truth
Conceptually speaking, Object is defined as the root object of all objects and is the most basic unit (reference) of the concept of "object-oriented". If it is removed, the entire concept will collapse;
Can you imagine matter without molecules/atoms?
No matter you create it with new or use literals, the compiler will automatically recognize the ancestor of the object
Yeah, null exception, this thing itself is a special case. js treats it as an object at the beginning, and then the so-called "empty object" phenomenon will appear in the subsequent Object.create(null). If it is defined at the beginning is a special value, then there is no such thing as Object.create(null). So in my understanding, this "empty object" is self-consistent and connected in definition, and should not be classified as "object-oriented" In this concept.