I'm trying to make one constructor function parent of another constructor function.
function Fruit() {
this.isEatable = function() {
return eatable;
};
}
function Apple(eatable , sweet) {
this.isSweet = function() {
return sweet;
};
var instance = {};
Fruit.apply(instance);
_.extend(this, instance);
}
var a = new Apple(true, false);
console.log(a.isEatable()); // Uncaught ReferenceError: eatable is not defined
But as you can see I get an error , what is the reason ? What is the better way to make one function inherit from another function ?
I also tried the following , and I still get the same error :
function Fruit() {
this.isEatable = function() {
return eatable;
};
}
function Apple(eatable , sweet) {
this.isSweet = function() {
return sweet;
};
}
_.extend(Apple.prototype , Fruit.prototype);// I use lodash library
var a = new Apple(true, false);
console.log(a.isEatable()); // Uncaught ReferenceError: eatable is not defined