js原型链继承及调用父类方法

function Rect(config){}
Rect.prototype.area = function(){ alert("我是父方法"); } function myRect(config){ arguments.callee.prototype.constructor.prototype.area(); //子类里调用父方法area arguments.callee.prototype.area();//子类里调用重载方法area } myRect.prototype = new Rect(); myRect.prototype.area = function(){ alert("我是重载方法"); } var rectObj = new myRect(); rectObj.constructor.prototype.area();//子类实例调用父类方法area rectObj.area();//子类实例调用子类方法area
 1  var Parent= function () {
 2 
 3     };
 4 
 5     Parent.prototype.process = function(){
 6         alert('parent method');
 7     };
 8 
 9     var Child= function () {
10         Parent.call(this);
11     };
12 
13     Child.prototype = new Parent();
14     Child.prototype.process = function(){
15          this.constructor.prototype.process();
16          alert('child method');
17     };
18 
19     var childVar = new Child();
20     childVar.process();
 

猜你喜欢

转载自www.cnblogs.com/catgatp/p/9096103.html