面向对象的特征是封装 继承 多态 封装
function animal() {
var name;
this.eat = function eat()
{ return 0; }
}
//继承
function cat() {
}
cat.prototype = new animal();
function cat() {
this.eat = function eat()
{ return 0; }
}
cat.prototype = new animal();
function dog() {
this.eat = function eat()
{ return 0; }
}
dog.prototype = new animal();
//多态
var cat1 = new cat(); cat1.name = "jiafei";
var dog1 = new dog(); dog1.name = "odi";
var list = [cat1, dog1];