Home  >  Article  >  Web Front-end  >  Detailed analysis and answers to js prototype chain inheritance and calling parent class methods

Detailed analysis and answers to js prototype chain inheritance and calling parent class methods

亚连
亚连Original
2018-05-17 10:21:361985browse

Below I will give you a detailed analysis and answerjsPrototype chainInheritance and calling the parent class method. I hope it will be helpful to everyone in the future.

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();//子类实例调用父类方法arearectObj.area();//子类实例调用子类方法area

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

In-depth explanation of js overwriting original methods and providing rewriting methods

Javascript simulates overloading, rewriting of toString method Written detailed answer

#Detailed explanation of JS rewriting prototype object

The above is the detailed content of Detailed analysis and answers to js prototype chain inheritance and calling parent class methods. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn