Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is prototype.constructor for?

Tags:

javascript

In continuation of this question, what is prototype.constructor for?

I thought that by simply doing:

new some_object()

that the function object became a constructor. I don't understand why you would need to set it in this manner.

some_object.prototype.constructor = some_object;
like image 922
jack mulraney Avatar asked Dec 06 '25 05:12

jack mulraney


1 Answers

Suppose class A inherit B using the following:

A.prototype = new B();

After this A.prototype.constructor == B. So instances of A have a constructor from B. It's a good practice to reset a constructor after the assignment.

like image 161
vbo Avatar answered Dec 07 '25 19:12

vbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!