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>
相关推荐
名为沙丁鱼的猫72911 小时前
【审计日志组件实践复盘】前端工程化 + 后端DDD架构(AOP切面拦截日志) + MBG
前端·架构
xqqxqxxq12 小时前
AI智能旅游规划系统 - 前端技术笔记
前端·笔记·旅游
陈随易18 小时前
bm2,MoonBit实现的pm2替代品
前端·后端·程序员
a11177620 小时前
农业数字孪生大屏网页 html开源
前端·html
圣光SG21 小时前
web操作题练习(六)
前端
闪亮的路灯1 天前
威联通QTS使用自带web服务期代理前端(类似nginx)
前端·nginx·威联通
kyriewen1 天前
我用AI写了半年代码——回头看,这5个能力正在退化
前端·javascript·ai编程
IT_陈寒1 天前
Vite静态资源路径这个坑差点让我加班到凌晨
前端·人工智能·后端
掘金酱1 天前
「TRAE Work 实战帮」征文启动!你沉淀的经验,值得被看见!
前端·人工智能·后端
橙子家1 天前
Windows 上同时安装多个 node 版本
前端