I am currently reading ‘Javascript Good Parts’, and I came across the following paragraph
If we try to retrieve a property value from an object, and if the
object lacks the property name, then JavaScript attempts to retrieve
the property value from the prototype object. And if that object is
lacking the property, then it goes to its prototype, and so on until
the process finally bottoms out with Object.prototype.
If I create an object obj2 from obj1 as prototype, does that mean obj1 cannot be destroyed until obj2 also goes out of scope?
As long as you’ve built your object’s inheritance (linked the prototypes), I don’t think that the browser relies on your references to that object.
ex1 :
ex2 :
UPDATE:
This behaviour might be related to the fact that in javascript you can’t exactly destroy an object; you can only remove all references to it. After that, the browser decides how to deal with the unreferenced objects through it’s Garbage collector.