首页 > 其他 > 详细

面向对象编程

时间:2018-01-09 15:10:26      阅读:199      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>面向对象编程</title>
    <meta charset="utf-8" />
</head>
<body>    
    <script>
        var person = {
            name: "张三",
            age: 18,
            getName: function () {
                return this.name;
            }
        }
    </script>
    <script>
        function parent() {
            this.name = "张三";
            this.show1 = function () {
                alert("我是" + this.name);
            }
        }
        function child() {
            this.age = 18;
            this.show2 = function () {
                alert("我的年龄是"+this.age)
            }
        }
        child.prototype = new parent();//child继承parent
        var test = new child();
        test.name = "李四";//继承父对象的name属性,并修改属性值
        test.show1();//继承父对象的show1()方法
        test.show2();//调用子对象的show2()方法
    </script>

</body>
</html>

 

面向对象编程

原文:https://www.cnblogs.com/zhang1997/p/8251473.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!