zoukankan      html  css  js  c++  java
  • (三十三)设计模式之混合模式

    /** * 混合模式 = 原型模式 + 构造函数模式 */ 
    function Animal(name, color){ 
        this.name = name; 
        this.color = color; 
        console.log( this.name + this.color) 
    } 
    Animal.prototype.getInfo = function(){ 
        console.log('名称:'+ this.name); 
    } 
    function largeCat(name, color){ 
        Animal.call(null, name, color); 
        this.color = color; 
    } 
    largeCat.prototype = create(Animal.prototype); 
    function create (parentObj){ 
        function F(){} 
        F.prototype = parentObj; 
        return new F(); 
    }; 
    largeCat.prototype.getColor = function(){ return this.color; } 
    var cat = new largeCat("Persian", "白色"); console.log( cat )
    

      

  • 相关阅读:
    ios本地推送
    ios BUG
    性能优化
    数据结构设计
    代码的可维护性
    NSMutalbleDictionary
    NSDictionary
    NSMutableArray
    java 容器
    Java bug
  • 原文地址:https://www.cnblogs.com/bgwhite/p/9405790.html
Copyright © 2011-2022 走看看