Just invoke the Base
function, like this
function Base (string) {
this.color = string;
}
function Sub (string) {
Base.call(this, string);
}
Using the Function.prototype.call
, you are setting the current object to the Base
function call as the current object in Sub
. So, Base
will be actually creating the color
property in Sub
object only.
Also, the prototype of an Object should depend only on the prototype of other objects, not on others objects. So, you would want to inherit with the common way
Sub.prototype = Object.create(Base.prototype);