Assign your prototype to an instance of your parent and make sure to call the parent constructor in the child constructor:
var Person = function (name, age){
this.name = name || "UNKNOWN";
this.age= age || "UNKNOWN";
}
Person.prototype.sayHello = function() {
console.log("Hello, my name is " + this.name + " and I am " + this.age + " years old");
};
var Employee = function(name, age, id) {
Person.call(this, name, age);
this.id = id || 'UNKNOWN';
};
Employee.prototype = new Person();
Employee.prototype.getHired = function() {
console.log('ZOMG I GOT HIRED! My ID # is:', this.id);
};
Some examples of using it:
var bob = new Person('Bobby', 25);
console.log(bob.name); //Bobby
console.log(bob.age); //25
console.log(bob.id); //undefined
bob.sayHello(); //Hello, my name is Bobby and I am 25 years old
var suse = new Employee('Susan', 32, 1337);
console.log(suse.name); //Susan
console.log(suse.age); //32
console.log(suse.id); //1337
suse.sayHello(); //Hello, my name is Susan and I am 32 years old
suse.getHired(); //ZOMG I GOT HIRED! My ID # is: 1337