2*/
3var p=new Employee('mxh',20);
1function Person(name)
2{
3 this.name=name
4}
5Person.prototype.sayHello=function()
6{
7 alert(this.name);
8}
9function Employee(name,age)
10{
11 Person.call(this,name);
12 this.age=age;
13}
14Employee.prototype=new Person();//将Employee的prototype设置为Person的prototype,并用Employee.prototype作为this调用Person函数
Code
1function Person(name)
2{
3 this.name=name
4}
5Person.prototype.sayHello=function()
6{
7 alert(this.name);
8}
9function Employee(name,age)
10{
11 Person.call(this,name);
12 this.age=age;
13}
14Employee.prototype=new Person();//将Employee的prototype设置为Person的prototype,并用Employee.prototype作为this调用Person函数