- function person(name){
- this._name=name;
- }
- person.talk=function(){
- document.write("I talk");
- }
- person.prototype.say=function(){
- document.write("my name is "+this._name);
- }
- function man(name,sex){
- person.call(this,name);
- this._sex=sex;
- }
- man.prototype=new person(); //这一步是实现man继承person的say方法的关键
- //但是这里依然会产生不必要的person里面的属性
- man.prototype.shout=function(){
- document.write("my name is "+this._name);
- document.write("my sex is "+this._sex);
- }
- var mm=new man("lee","man");
- mm.say();
- mm.shout();
- //mm.talk(); //this is error