functionParent(){this.name ='Parent';}Parent.prototype.sayHello=function(){
console.log('Hello, I am '+this.name);}functionChild(){}Child.prototype =newParent();var child =newChild();
child.sayHello();// Hello, I am Parent
functionParent(name){this.name = name;}Parent.prototype.sayHello=function(){
console.log('Hello, I am '+this.name);}functionChild(name, age){Parent.call(this, name);// 调用父类构造函数this.age = age;}var child =newChild('Child',10);
child.sayHello();// Error: child.sayHello is not a function