_.extend
is defined like this,
_.extend = function(obj) {
each(slice.call(arguments, 1), function(source) {
if (source) {
for (var prop in source) {
obj[prop] = source[prop];
}
}
});
return obj;
};
All it does is, iterate over the attributes of all the elements from the argument at index 1 till the end and add it to the first argument passed to it.
So, technically, what you have done will have the same effect, but with one subtle difference.
When you use _.extend
, you are augmenting the Dog.prototype
object, when you assign to it (like in your second example), you are replacing the Dog.prototype
object with some other object.