Whats the difference between
Employee.prototype = Object.create(Person.prototype);
and
_.extend(Employee.prototype, Person.pr
With Employee.prototype = Object.create(Person.prototype);
you are completely replacing the Employee.prototype
.
But with _.extend(Employee.prototype, Person.prototype);
you are adding the Person.prototype
on top of the Employee.prototype
.
For example,
var a = {var1:1, var2:2};
var b = {var2:4, var3:3};
console.log(_.extend(a, b)); // {var1:1, var2:4, var3:3}
As you see, a
it's not completely replaced by b
, it's just extended by the properties defined in b
.