5. class--extends

 ES5:

function article(x,y){
this.x = x;
this.y = y;
}
article.prototype.say = function() {
return (this.x + "的年纪=" + this.y)
}
var person = new article('hulk',12);
console.log(person.say())

 

ES6

class People {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }
  say() {
    alert("hello")
   }
}

class lily extends People {
  constructor() {
    super( )
  }
  goodbye() {
    alert("goodbye")
  }
}
var q = new People;
q.say();// hello

var p = new lily;
p.say(); //hello

posted @ 2018-09-06 14:48  大耳朵小虎  阅读(100)  评论(0编辑  收藏  举报