Both ES6 class and prototype of function have a contructor
, but I\'m wondering are they the same? Let me give more explanations.
So, I create a Cat function
Since classes are just a syntactic sugar over prototype inheritance, is the constructor function in Dog class just the same as in Cat function?
Yes, the constructor-prototype relationship still works the same.
There are a few differences though, for example Dog.prototype
is not writable and Dog
can only be called with new
.