zoukankan      html  css  js  c++  java
  • 面向对象编程思路

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title>面向对象编程思路</title>
        </head>
    
        <body>
        </body>
        <script type="text/javascript">
            // 把大象放进冰箱,需要几个步骤
    
            /*
            // ------------- 面向过程的编程思路 -------------
            // false : 门是关闭状态   true : 门是开启的状态
            var door = false;
            // false : 冰箱无物   true : 冰箱有物
            var box = false;
            
            // 第一步 : 打开冰箱的门
            function openDoor(){
                door = true;
            }
            openDoor();
            // 第二步 : 把大象放进去
            function putElephant(){
                if(door){
                    if(box){
                        box = false;
                    }
                    if(!box){
                        box = true;
                    }
                }
            }
            putElephant();
            // 第三步 : 把门关上
            function closeDoor(){
                if(door){
                    door = false;
                }
            }
            closeDoor();
            */
            // ---------------- 面向对象的编程思路 ------------------
    
            function Box(door, box) {
                this.door = door;
                this.box = box;
            }
            Box.prototype.openDoor = function() {
                this.door = true;
                return this;
            }
            Box.prototype.putElephant = function() {
                if(this.door) {
                    this.box = true;
                }
                return this;
            }
            Box.prototype.closeDoor = function() {
                if(this.door) {
                    this.door = false;
                }
                return this;
            }
            // 调用
            var box = new Box(false, false);
             box.openDoor();
             box.putElephant();
            box.closeDoor();
        </script>
    
    </html>
  • 相关阅读:
    Rundll32
    ASP.NET MVC3 中整合 NHibernate3.3、Spring.NET2.0 时 Session 关闭问题
    页面内容排序插件jSort的使用
    jQuery实现等比例缩放大图片
    CSS 样式使用
    AspNetPager 样式以及使用(漂亮)
    怎么提高Jquery性能
    java 常见下载合集
    ES6 rest参数和扩展运算符
    21.Decorator修饰器
  • 原文地址:https://www.cnblogs.com/zbly/p/10175619.html
Copyright © 2011-2022 走看看