javascript 封装

封装

类名首字母大写

this   +  prototype

var Cat ={

  name:'';

  color:'';

}  

/**

* this

*/

var Cat=function(name,color){

  this.name = name;

  this.color = color;

}

/**

*prototype

*/

Cat.prototype.type = "猫科动物";

Cat.prototype.eat = function(){alert("吃老鼠")};

 

var cat1 = new Cat('haha','xxx');

posted @ 2017-02-23 17:08  黄鹂  阅读(99)  评论(0编辑  收藏  举报