记得开心=。=|

Js继承之组合模式

组合模式

  • 前置知识 原型 原型链 apply

举个例子

function Person(name, age) {
    this.name = name??"";
    this.age = age??"";
};

Person.prototype.say = function () {
    console.log('我的名字是' + this.name + ',今年' + this.age + '岁')
}

function Student(name, age, gender, score) {
    Person.apply(this, [name, age]);
    this.gender = gender??"";
    this.score = score??"";
}
Student.prototype = new Person();

console.log(new Student('ZhangSan', 20, '男', 100));

本文作者:HuangBingQuan

本文链接:https://www.cnblogs.com/bingquan1/p/18416515

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   HuangBingQuan  阅读(3)  评论(0编辑  收藏  举报
历史上的今天:
2023-09-16 Es6-符号
2022-09-16 将数组中的对象 按照对象中某个值 进行排序
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 不将就 码农权
  2. 2 Bleeding Love 码农权
  3. 3 想你念你 码农权
Bleeding Love - 码农权
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

Not available