js-对象封装

function Cat (name,age) {

 this.name = name;

this.age = age;

}

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

Cat.prototype = {

say:function(){

console.log("喵咪~~~");

},

run:function(r){

console.log("我的跑动速度是:"+r);

}

}

var c = new Cat();

你可能感兴趣的:(js-对象封装)