(三十三)设计模式之混合模式
生活随笔
收集整理的這篇文章主要介紹了
(三十三)设计模式之混合模式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/** * 混合模式 = 原型模式 + 構造函數模式 */
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 )
轉載于:https://www.cnblogs.com/bgwhite/p/9405790.html
總結
以上是生活随笔為你收集整理的(三十三)设计模式之混合模式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 数据集转换树、递归重组节点信息多
- 下一篇: 移动端 | table 布局