<!DOCTYPE HTML>
<html>
<head>
<title>please enter your title</title>
<meta charset="utf-8">
<meta name="Author" content="潭州学院-阿飞老师">
<style type='text/css'>
*{ margin:0; padding:0;}
</style>
</head>
<body>
<script type="text/javascript">
//父类
function Person( name ){ // 构造函数 就是 类
this.name = name;
}
Person.prototype.showName = function(){
alert( this.name );
}
var p1 = new Person( 'Eva' );
//子类
function PersonPlus( name , age ){
Person.call( this , name );
this.age = age;
}
var Fn = function(){};
Fn.prototype = Person.prototype;
PersonPlus.prototype = new Fn();
PersonPlus.prototype.consturctor = PersonPlus;
// PersonPlus.prototype = Person.prototype
PersonPlus.prototype.showAge = function(){
alert( this.age )
}
var p2 = new PersonPlus('Eva' , 15);
alert( p2.constructor )
</script>
</body>
</html>
js原型继承机制实例详解
最新推荐文章于 2021-08-11 09:45:21 发布