zoukankan      html  css  js  c++  java
  • 组合继承

    * 原型实现继承
    * 借用构造函数实现继承
    * 组合继承:原型继承+借用构造函数继承
    * */
    function Person(name,age,sex) {
    this.name=name;
    this.age=age;
    this.sex=sex;
    }
    Person.prototype.sayHi=function () {
    console.log("你好啊,嘻嘻嘻");
    };
    function Studeny(name,age,sex,score) {
    //借用构造函数:属性值重复的问题
    Person.call(this,name,age,sex,score);
    this.score=score;
    }
    //改变原型指向====》继承
    Studeny.prototype=new Person();//不传值
    Studeny.prototype.eat=function () {
    console.log("吃好吃的");
    };
    var stu1=new Studeny("小美",20,"女","100");
    console.log(stu1.name,stu1.age,stu1.sex,stu1.score);
    stu1.sayHi();
    stu1.eat();
    var stu2=new Studeny("小丽",22,"女","120");
    console.log(stu2.name,stu2.age,stu2.sex,stu2.score);
    stu1.sayHi();
    stu1.eat();
  • 相关阅读:
    day08超市商品库存案例
    day07
    day06_03
    day06_02
    day06_01
    最简单的库存管理java案例
    Day05_homework
    方法的使用注意事项
    day05
    冒泡排序
  • 原文地址:https://www.cnblogs.com/lujieting/p/10067327.html
Copyright © 2011-2022 走看看