zoukankan      html  css  js  c++  java
  • JS设计模式

    单例模式

    var single =(function(){
        var unique;
        function getInstance(){
           if(unique===undefined){
                unique=new Construct();
            } 
            return unique;
        }
        function Construct(){
           
        }
        return{
             return getInstance:getInstance
        }
    })();        

    构造函数模式:

    function Car (color,price,brand){
      if(!(this instanceof Car)){
        return new Car(color,year,brand);
      }
      this.color=color;
      this.price=price;
      this.brand=brand;
      this.output=function(){
        return this.color+"-"+this.price+this.brand;
      }
    }
    var tom = new Car('1','2','3');
    tom.output();

    建造者模式:

    function workerBuilder(){
      this.workOne=function(){
        //建房子的骨架
      }
      this.workTwo=function(){
        //建厨房
      }
      this.workThree=function(){
        //建客厅
      }
      this.workFour=function(){
        //建卧室
      }
      this.getResult=function(){
        var house = new house();
        return house;
      }
    }
    
    
    function Director(){
      this.coustruct=function(builder){
        builder.workOne();
        builder.workTwo();
        builder.workThree();
        builder.workFour();
      }
    }
    
    function House(){
      this.houseFrame="";
      this.houseKitchen="";  
      this.houseRoom="";
      this.linvingRoom="";
    }
    
    var builder = new workerBuilder;
    var director=new Director();
    director.coustruct(builder);
    var house = new House();
  • 相关阅读:
    C#面向对象
    C#语句
    C#语言数据类型
    Jupyter Notebook(iPython)
    BeautifulSoup模块
    requests模块
    爬虫基本原理
    版本控制系统
    支付宝支付
    django内置组件——ContentTypes
  • 原文地址:https://www.cnblogs.com/littlewriter/p/7130380.html
Copyright © 2011-2022 走看看