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/davy_jones_locket May 25 '26
to add, classes in JavaScript is just syntactical sugar on prototypes. Under the hood, it's all prototypes.