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>
相关推荐
恋猫de小郭1 小时前
AGENTS.md 真的对 AI Coding 有用吗?或许在此之前你没用对?
前端·人工智能·ai编程
sunny_3 小时前
构建工具的第三次革命:从 Rollup 到 Rust Bundler,我是如何设计 robuild 的
前端·rust·前端工程化
rfidunion4 小时前
springboot+VUE+部署(12。Nginx和前端配置遇到的问题)
前端·vue.js·spring boot
珹洺4 小时前
Java-servlet(五)手把手教你利用Servlet配置HTML请求与相应
java·运维·服务器·前端·servlet·html·maven
FYKJ_20104 小时前
springboot大学校园论坛管理系统--附源码42669
java·javascript·spring boot·python·spark·django·php
QQ24391974 小时前
语言在线考试与学习交流网页平台信息管理系统源码-SpringBoot后端+Vue前端+MySQL【可直接运行】
前端·spring boot·sql·学习·java-ee
范特西.i5 小时前
QT聊天项目(6)
前端
a1117765 小时前
水体渲染系统(html开源)
前端·开源·threejs·水体渲染
程序员小李白5 小时前
CSS 盒子模型
前端·css·html
Zzz不能停5 小时前
单行 / 多行文本显示省略号(CSS 实现)
前端·css