1.

What are Map and WeakMap?

Answer»

Prototype chain can be EXPLAINED through below example. Here we have three functions MAMMALWhale and BlueWhale. Each have their own version of print().

We are inheriting from Mammal to Whale by SETTING Whale’s prototype to be Mammal’s prototype.
Then inhering from Whale to BlueWhale by setting BlueWhale’s prototype to be Whale’s prototype.

Then we have three instances of Mammal, Whale and BlueWhale. On calling the print(), we get the RESPECTIVE console log.

Now, let remove BlueWhale’s print() method and then if we call print() on its instance blueWhale, we get result from Whale’s print().

If we further remove Whale’s  print() method and then if we call print() on its instance blueWhale, we get result from Mammal’s print().

So, if you call an method on a Child and the method is not there, it will check in its Parent and if not there then will check in Parent’s parent.



Discussion

No Comment Found