r/learnjavascript • u/envyslth • May 25 '26
What is the difference?
Im wondering what the difference between
function Dog(){
…
this.bark = function(){…}
}
And
function Dog {
…
}
Dog.prototype.bark = function() {
…
}
Is and what the advantages of either of them Are.
13
Upvotes
View all comments
Show parent comment
2
u/scritchz May 25 '26
Under the hood, it works basically the same, yeah.
But they do have their differences, which is why you should prefer classes over constructor functions.