jsプロトタイプ継承メカニズムの実例を詳しく説明する.


<!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>