I'm seeing a lot of this these days:
function Dog () {
this.name = 'Fido';
}
_.extend(Dog.prototype, {
bark: function() {
return 'BARK, BARK!'
},
soilChothingWithDirtyPaws: function () {
// Some intricated logic here
return 'There, I did it!';
}
});
But is the result different from the code below?
function Dog () {
this.name = 'Fido';
}
Dog.prototype = {
bark: function() {
return 'BARK, BARK!'
},
soilChothingWithDirtyPaws: function () {
// Some intricated logic here
return 'There, I did it!';
}
}
I know what underscore's extend function is supposed to do, but I don't really get the point of doing this in the object's prototype - when you could do this with plain old vanilla JS, that means, I can't see why a man in the middle is needed here. I wonder if I'm missing something really neat.
Does that bring any good at all?
It would be really nice if somebody clear things out. Thanks a lot!