search

Home  >  Q&A  >  body text

javascript - Does an object have nothing to do with the constructor after it is instantiated? Can I only find the prototype object if I want to modify it?

After an object has been instantiated, if you want it to have new attributes, can you only add them through prototype? Why can't the constructor be modified?
Is the reason because after an object has been instantiated, the existence of its properties and methods has nothing to do with the constructor?

阿神阿神2747 days ago533

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-19 10:31:49

    Prototype is called the prototype chain.
    1. After an object is instantiated, it can be added directly using Object.name. As for those added through the prototype chain, they are public properties added, which can be accessed by other objects through the same class instance.
    2. The instantiated object cannot access the prototype chain. The prototype chain is only available in Class, and the attributes and methods of the prototype chain are added through Class.prototype. The constructor also belongs to the prototype chain method. You can modify the constructor you obtain after passing the instance, but it cannot affect the constructor of Class and will change as Class.prototype changes.
    As for the instantiated object that wants to use the properties and methods defined in the prototype chain, you can use Object.name directly.
    You can go and read about the prototype chain, there are a lot of them on Baidu.
    I am also a newbie, so I would like to point out any shortcomings.

    reply
    0
  • Cancelreply