合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
**JS类继承** ~~~ function people(){ var $this = this; $this.old = "老人"; $this.yang="青年"; $this.number = function(){ return $this.old; } } people.prototype.boy ="男孩"; function student(name,age) { var $p_this = this; $p_this.nameS = name; $p_this.age = age; $p_this.number = function(){ return getName(); } function getName(){ return $p_this.nameS; } function getAge(){ return $p_this.age; } } student.prototype.sex="男"; student.prototype.number = function(){ console.log("20170101"); } var stu1 = new student("小马",21); var stu2 = new student("小明",30); console.log(stu1.number()); function extend(student, people) { var F = function(){}; F.prototype = people.prototype; student.prototype = new F(); student.prototype.constructor = student; student.uber = people.prototype; // student.super = people.prototype; } extend(student, people); var stu1 = new student("小马",21); console.log(stu1.number()); console.log(stu1.boy); ~~~