JavaScript inheritance of several implementations?

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_44721831/article/details/102642437

How Javascript implementation inheritance?

1, the configuration of inheritance
2, prototype inheritance
3, inheritance Example
4, copy inheritance

Apply and call mechanism or method to achieve relatively simple prototype prototype, prototype recommended constructor and mixed mode.

    function Parent(){                                  
		this.name = 'wang';                             
	}                                                   
                                                        
	function Child(){                                   
		this.age = 28;                                  
	}                                                   
	Child.prototype = new Parent();//继承了Parent,通过原型     
                                                        
	var demo = new Child();                             
	alert(demo.age);                                    
	alert(demo.name);//得到被继承的属性                         

JavaScript inheritance of several implementations?

Guess you like

Origin blog.csdn.net/qq_44721831/article/details/102642437