var Person = function(firstName, lastName, age, gender){
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.gender = gender;
this.eat = function(){
console.log("eating...");
}
this.sleep = function(){
console.info("sleepping...");
}
}
var Employee = function(company, salary){
this.company = company;
this.salary = salary;
this.work = function(){
console.warn("working...");
}
}
// 将Employee的原型对象作为Person对象。
// 所以新类的实例将继承Employee.prototype
// 后者又由Person.prototype继承而来。
// Person.prototype又由Object.prototype继承而来。
Employee.prototype = new Person;
// 上面覆盖了js提供的原型对象,抛弃了给定的constructor属性
// Employee对象继承了它的超类的constructor属性,却没有自己的
// 明确设置如下
Employee.prototype.constructor = Employee;
var e1 = new Employee("华为", 20000);
var e2 = new Employee("谷歌", 30000);
var e3 = new Employee("百度", 10000);
e1.eat();e1.sleep();e1.work();
e2.eat();e2.sleep();e2.work();
e3.eat();e3.sleep();e3.work();