web前端全系列 教程
1839个小节阅读:2242.8k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
JavaScript 不提供多重继承功能,即不允许一个对象同时继承多个对象。但是,可以通过变通方法,实现这个功能
xxxxxxxxxx
function Sxt() {
this.hello = 'hello';
}
function Itbaizhan() {
this.world = 'world';
}
function Sum() {
Sxt.call(this);
Itbaizhan.call(this);
}
// 继承 Sxt
Sum.prototype = Object.create(Sxt.prototype);
// 继承链上加入 Itbaizhan
Object.assign(Sum.prototype, Sum.prototype);
// 指定构造函数
Sum.prototype.constructor = Sum;
var s = new Sum();
console.log(s.hello); // 'hello'
console.log(s.world); // 'world'
实时效果反馈
1. 下列是实现多重继承,划横线处应该填写代码是:
xxxxxxxxxx
function Sxt() {
this.hello = 'hello';
}
function Itbaizhan() {
this.world = 'world';
}
function Sum() {
Sxt.call(this);
Itbaizhan.call(this);
}
Sum.prototype = ___(Sxt.prototype);
___(Sum.prototype, Sum.prototype);
A call concat
B Object.create Object.assign
C call Object.assign
D Object.create concat
答案
1=>B