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?
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 thisBrendan Eich
.
I think you should first tell me what you define as 空對(duì)象
.
According to your title description, I guess what you mean by 空對(duì)象
應(yīng)該是指最原始的那個(gè)對(duì)象原型吧?這個(gè)東西是有的,它是null
should refer to the original object prototype, right? This thing exists, it is null
, and it is the end of the prototype chain of all objects.
js has empty objects
Object.create(null);
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.