es6的class属性方法

xml 复制代码
<!DOCTYPE html>
<html>
    <head>
       <meta charset="utf-8" />
       <title>class属性方法</title>
    </head>
    <body>
       <script>
          class Pesion{
             constructor(name,age){
                this.name=name;
                this.age=age;
             }
             //实例方法
             say(){
                console.log(this.name,this.age);
             }
          }
          let p=new Pesion("张三",20);
           p.say()
          //静态属性和方法
          class Pesion {
             constructor(name, age) {
                this.name = name;
                this.age = age;
             }
             //静态方法
             static say() {
                console.log("静态方法被调用");
             }
          }
          Pesion.say()
          class Perple{
             //静态方法的this指向类,而非类的实例
             static staticSay(){
                this.say()//调用静态方法
             }
             static say(){
                console.log("静态say方法");
             }
             say(){
                console.log("普通方法");
             }
          }
          Perple.staticSay()
          //静态属性
          class Student{}
          Student.age=100
          console.log(Student.age);
       </script>
    </body>
</html>
相关推荐
洋不写bug18 小时前
html实现简历信息填写界面
前端·html
三十_A18 小时前
【无标题】
前端·后端·node.js
excel18 小时前
Vue 编译器源码解读:transformVBindShorthand 的设计与原理
前端
时间的情敌19 小时前
Vue3的异步DOM更新:nextTick的正确使用方法
前端·javascript·vue.js
风语者日志19 小时前
[LitCTF 2023]作业管理系统
前端·网络·安全·web安全·ctf
excel19 小时前
深入解析:Vue 编译器核心工具函数源码(compiler-core/utils.ts)
前端
excel19 小时前
第五章:辅助函数与全流程整合
前端
excel19 小时前
🔍 深度解析:Vue 编译器中的 validateBrowserExpression 表达式校验机制
前端
excel19 小时前
深度解析:Vue 模板编译器中的 Tokenizer 实现原理
前端
excel19 小时前
🧩 Vue 编译核心:transform.ts 源码深度剖析
前端