浅谈javaScript继承

原型和构造函数


  • prototype属性对Object添加属性和方法
function Aoo(){}
console.log(Aoo.prototype instanceof Object)
//true
  • 构造函数实例化过程
function Aoo(name){
  this.name = name
}
  var aoo = new Aoo('las')
  console.log(aoo)
//输出Aoo {name: "las"}

原型和继承


  • 简单继承
function Aoo(name){
   this.name = name
}
function Boo(name,age){
   this.Obj = Aoo
   this.Obj(name)
   this.age = age
}
  • 继承
function Aoo(name){
   this.name = name
}
Aoo.prototype.a = "a"
function Boo(name,age){
this.name = name
Aoo.call(this.name)
}
Boo.prototype.boo1 = function(){
  console.log(boo1)
}
Boo.prototype.boo2 = function(){
  console.log(boo2)
}
Boo.prototype.constructor = Boo
  var obj = new Boo('las','20')

你可能感兴趣的:(浅谈javaScript继承)