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?
阿神
阿神 2017-05-19 10:29:49
0
1
438

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?

阿神
阿神

闭关修行中......

reply all (1)
大家讲道理

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.

    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!