I am currently working on implementing a JavaScript inheritance example that I came across, but I am encountering issues with the child object not constructing as expected. When attempting to create the jill instance in the code snippet below, it does not return a Jill object, leading to difficulties in calling methods from either the child or parent.
var Person = function() {
this.name = "unnamed";
}
Person.prototype.sayName = function() {
console.log("My name is " + this.name);
}
var Jill = function() {
var jill = function() {
Person.call(this);
this.name = "Jill";
};
jill.prototype = Object.create(Person.prototype);
jill.prototype.constructor = jill;
jill.prototype.expressJoy = function() {
console.log("Huray!");
};
return jill;
}
var jill = new Jill();
console.log(jill instanceof Jill); // false
jill.expressJoy(); // error, is not a function
jill.sayName(); // error, seen if comment out previous line