class继承

xml 复制代码
<script>
    class Point {
       constructor(x, y) {
          this.x = x
          this.y = y
       }
       say() {
          console.log("我父类方法");
       }
    }
    class ColorPoint extends Point {
       //子类继承父类,必须实现构造函数
       constructor(x,y,z){
          super(x,y)
          this.z = z  
       }
       hi(){
          super.say()//调用父类方法
       }
    }
    const p = new ColorPoint(10,20)
    p.hi()
    // console.log(p.x);
</script>
相关推荐
excel7 小时前
为什么我推荐使用 Termius:现代 SSH 工具的完整体验
前端·后端
ZC跨境爬虫7 小时前
模块化烹饪小程序开发日记 Day7:(菜谱详情接口开发与JSON数据读取全流程)
前端·javascript·css·ui·微信小程序·json
এ慕ོ冬℘゜8 小时前
JS 前端基础面试题
开发语言·前端·javascript
LaughingZhu8 小时前
Product Hunt 每日热榜 | 2026-05-25
前端·人工智能·经验分享·chatgpt·html
IT_陈寒9 小时前
Java的Optional差点让我掉坑里,这几个坑你别踩
前端·人工智能·后端
粉嘟小飞妹儿9 小时前
JavaScript对象创建的几种灵活方法
前端
前端小万9 小时前
2026年了,为什么我突然开始做GZH?
前端
子兮曰9 小时前
Harness 驾驭工程深度教程:从 AGENTS.md 到全链路 AI 编码基础设施
前端·后端·ai编程
木子雨廷10 小时前
Flutter 桌面小组件开发
前端·flutter
还有多久拿退休金10 小时前
我在自家页面嵌了个 iframe,结果对方说"你不配"——跨域和 CSP 的那些坑
前端·架构