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>
相关推荐
copyer_xyf18 小时前
Python 文件基本操作
前端·后端·python
x***r15118 小时前
linux安装 redis-5.0.5.tar.gz 详细步骤(源码编译、配置、启动)
前端
程序员小羊!18 小时前
01HTML预备知识
前端·html
xkxnq18 小时前
第八阶段:工程化、质量管控与高级拓展(130天),Vue端到端测试:Cypress自动化测试(登录流程+表单提交+页面跳转)
前端·vue.js·flutter
小雨下雨的雨18 小时前
基于鸿蒙PC Electron框架技术完成的五子棋游戏 - 技术实现详解
前端·javascript·游戏·华为·electron·鸿蒙
cheems952718 小时前
[开发日记]Spring Boot + MyBatis-Plus 抽奖系统开发复盘:从奖品创建、活动校验到前端圈选人员失效的一次完整排障
前端·spring boot·mybatis
老毛肚18 小时前
jeecgboot vue API 拆分02
前端·javascript·vue.js
赵谨言19 小时前
基于C#的在线编码与自动化测试全栈Web平台的设计与实现
开发语言·前端·c#
Raink老师19 小时前
【AI面试临阵磨枪-98】前端如何展示多模态流式输出:文字打字机 + 图片渐进 + 音频播放?
前端·人工智能·面试
AI_零食19 小时前
奶茶大数据运维表 - 鸿蒙PC Electron框架技术实现详解
运维·前端·华为·electron·开源·harmonyos·鸿蒙