面向对象编程的特点:
1.抽象性:通过对象分析问题
2.封装性:属性以及方法 封装到对象中 节约维护成本 安全
3.继承性:JAVA,PYTHON 会讲继承性
4.多态性:一个类可以创建 多种对象 js基本用不到
继承性:父类 写公共的方法和属性 子类继承 节约代码
//父类 动物类
function Animal(name,age,color){
this.name=name
this.age=age
this.color=color
this.height=200
}
Animal.prototype.move=function(){
console.log(this.name+"正在跑")
}
Animal.prototype.eat=function(){
console.log(this.name+"正在吃")
}
//子类 老虎类
function Tiger(name,age,color){
Animal.call(this,name,age,color)
}
Tiger.prototype=new Animal()
Tiger.prototype.call=function(){
console.log(this.name+"嗷嗷嗷")
}
Tiger.prototype.chiren=function(){
console.log("吃人")
}
var t1=new Tiger("辛巴",21,"白色")
console.log(t1.name)
t1.move()