js原型继承机制实例详解

来源:互联网 发布:淘宝二加一正品 编辑:程序博客网 时间:2024/04/29 08:35
<!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>
0 0
原创粉丝点击