class语法

xml 复制代码
<script>
    /*
    es5类写法
     function Persion(name, age) {
       this.name = name,
          this.age = age
    }
    Persion.prototype.say = function() {
       console.log(this.name + "say");
    }
    let p = new Persion("贾维斯", 30)
    p.say()*/
    
    class Pesion {
       constructor(name, age, sex) {
          this.name = name
          this.age = age
          this.sex = sex
       }
       say() {
          console.log(this.name + "say");
       }
       get sexer() {
          return this.sex
       }
       set sexer(s) {
          this.sex= s
       }
    }
    let p = new Pesion("贾维斯", 30)
    p.say()
    p.sexer = "贾维斯1"
    console.log(p.sexer);
</script>
相关推荐
yuhaiqiang10 分钟前
被 AI 忽悠后,开始怀念搜索引擎了?
前端·后端·面试
红色石头本尊26 分钟前
1-umi-前端工程化搭建
前端
真夜33 分钟前
关于对echart盒子设置百分比读取的宽高没有撑开盒子解决方案
前端
楠木6851 小时前
RAG 资料库 Demo 完整开发流程
前端·ai编程
肠胃炎1 小时前
挂载方式部署项目
服务器·前端·nginx
像我这样帅的人丶你还1 小时前
使用 Next.js + Prisma + MySQL 开发全栈项目
前端
FPGA小迷弟1 小时前
FPGA 时序约束基础:从时钟定义到输入输出延迟的完整设置
前端·学习·fpga开发·verilog·fpga
Kel1 小时前
深入剖析 openai-node 源码:一个工业级 TypeScript SDK 的架构之美
javascript·人工智能·架构
毛骗导演1 小时前
@tencent-weixin/openclaw-weixin 插件深度解析(四):API 协议与数据流设计
前端·架构
毛骗导演1 小时前
@tencent-weixin/openclaw-weixin 插件深度解析(二):消息处理系统架构
前端·架构