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?

世界只因有你
世界只因有你

reply all (4)
我想大声告诉你

var obj = {}; is just a shorthand, equivalent to var obj = Object.create({});

Object.create(null); may be an empty object.

    淡淡烟草味
    1. You have to ask about thisBrendan Eich.

    2. I think you should first tell me what you define as空对象.

    3. 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.

      我想大声告诉你

      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.

          Latest Downloads
          More>
          Web Effects
          Website Source Code
          Website Materials
          Front End Template
          About us Disclaimer Sitemap
          php.cn:Public welfare online PHP training,Help PHP learners grow quickly!