Prototypal inheritance
function Person(name, title) {
this.name = name;
this.title = title;
this.subordinates = [];
}
function Employee(name, title) {
this.name = name;
this.title = title;
//this.sayHello = function() {
// console.log("Hello!");
//};
}
Employee.prototype = new Person();
// Now sayHello() is only in prototype but not in every Employee instance.
Employee.prototype.sayHello = function() {
console.log("Hello!");
};
emp1 = new Employee("name", "title");
emp2 = new Employee("name2", "title2");