call能够实现属性继承

    1. function Person(name,age){
    2. this.name = name;
    3. this.age = age;
    4. }
    5. function Teacher(name,age,skill){
    6. var self = this;
    7. Person.call(self,name,age)
    8. this.skill = skill;
    9. }
    10. var t = new Teacher("zhang",18,"js");
    11. console.log(t)
    1. 原型对象:Javascript的继承是基于原型的继承<br /> call能够实现属性的继承
    1. function Person(name,age){
    2. this.name = name;
    3. this.age = age;
    4. }
    5. Person.prototype.sayName = function(){
    6. console.log(this.name)
    7. }
    8. function Teacher(name,age,skill){
    9. Person.call(this,name,age)
    10. this.skill = skill;
    11. }
    12. Teacher.prototype = Person.prototype;
    13. Teacher.prototype.sayAge = function(){
    14. console.log(this.age)
    15. }
    16. /* 方法的继承 */
    17. Teacher.prototype.constructor = Teacher;
    18. var t = new Teacher("zhang",18,"js");
    19. var p = new Person("lisi",13);
    20. console.log(t.constructor)
    1. 1.封装<br /> 2.继承<br /> 3.多态 (自带多态)
    1. function Person(name, age) {
    2. this.name = name;
    3. this.age = age;
    4. }
    5. Person.prototype.sayName = function () {
    6. console.log(this.name)
    7. }
    8. function Teacher(name, age, skill) {
    9. Person.call(this, name, age)
    10. this.skill = skill;
    11. }
    12. Teacher.prototype =Object.create(Person.prototype,{
    13. constructor:{
    14. value:Teacher
    15. }
    16. })
    17. Teacher.prototype.sayAge = function () {
    18. console.log(this.age)
    19. }
    20. var t = new Teacher("zhang", 18, "js");
    21. console.log(t.constructor)
    22. t.sayName();