js中用prototype实现继承

来源:互联网 发布:我的世界安卓版js 编辑:程序博客网 时间:2024/05/21 06:18

js中用prototype实现继承


<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script>        //prototype  模拟继承        function Person(name,age){            this.name=name;            this.age=age;        }        function Student(){            this.stuId=2222222;        }        Student.prototype=new Person("zhangsan",20);        var stu=new Student();        alert(stu.name);        alert(stu.age);    </script></head><body></body></html>


0 0
原创粉丝点击