Ai
1 Star 0 Fork 0

DragonHot/js-code

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ex3.js 606 Bytes
一键复制 编辑 原始数据 按行查看 历史
DragonHot 提交于 2022-01-10 23:15 +08:00 . 继承
function Point(x, y) {
this.x = x;
this.y = y;
this.arr = [x, y];
}
Point.prototype.print = function () {
console.log(`Point:(${this.x},${this.y})`);
};
function ColorPoint(x, y, color) {
Point.call(this, x, y);
this.color = color;
}
ColorPoint.prototype.printColor = function () {
console.log(`ColorPoint:(${this.x},${this.y}) ${this.color} [${this.arr}]`);
};
const cp = new ColorPoint(1, 2, "red");
// cp.print(); // 没有继承prit方法,报错
cp.printColor(); // ColorPoint:(1,2) red [1,2]
console.log(cp instanceof Point); // false
console.log(cp instanceof ColorPoint); // ture
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dragonhot/js-code.git
git@gitee.com:dragonhot/js-code.git
dragonhot
js-code
js-code
master

搜索帮助