Tell us what’s happening:
Consider the below approaches,
function Dog(name) {
this.name = name;
}
Dog.prototype.numLegs = 2;
function Dog(name) {
this.name = name;
this.numLegs = 2;
}
How approach 1 will help to reduce duplicate code versus approach 2?
Why are we using prototype instead of defining it inside constructor function?
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/use-prototype-properties-to-reduce-duplicate-code