(三十)设计模式之构造函数模式

 
/** * 构造一个动物的函数 */ 
function Animal(name, color){
     this.name = name;
     this.color = color; 
    this.getName = function(){ 
        return this.name;
     } 
}
 // 实例一个对象
 var cat = new Animal('猫', '白色'); console.log( cat.getName() );

  

posted @ 2018-08-02 10:48  狗尾草的博客  阅读(178)  评论(0编辑  收藏  举报