Skip to content
Advertisement

Object prototype is copied or referenced in JavaScript?

In the following code :

JavaScript

The user Object is the prototype of admin Object, As we see line (**) sets the fullName for admin Object, although user Object remains the way it was.

So is it correct to say that user Properties & Methods are copied to admin Object ?

Advertisement

Answer

Using Object.getOwnPropertyNames reveals that by using admin.fullName = "Alice Cooper" you actually create new properties instead of overriding anything.

JavaScript

Changing the the properties of the prototype reveals that it’s references

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement