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>
相关推荐
因_崔斯汀1 分钟前
用 AI 生成 Three.js 沉浸式网站,代码与 Skill 均已开源
前端·人工智能
葡萄城技术团队33 分钟前
一键触发工作表中所有异步函数:用依赖单元格刷新 SpreadJS 公式
前端
Bigger39 分钟前
谁动了我的 URL?——记一次微前端"灵异 Bug"的排查实录
前端·ai编程·vue-router
JavaGuide1 小时前
轻量开源版 IDEA 来了!
前端·后端
2601_962097481 小时前
JavaScript 异步编程
javascript·ajax·回调函数·异步编程·子线程
张洪权1 小时前
nest.js websocket 群聊----私聊功能
前端·nestjs
流光D1 小时前
AI Era: Building Web Sites and Configuring Nginx Reverse Proxy Process
前端·人工智能·nginx
sakidd1 小时前
VS Code 的 AI Chat 现在已经这么能干了?
前端
计算机魔术师1 小时前
英伟达砸130亿美元买下一个平台,黄仁勋到底在怕什么?
前端
全栈项目管理程序猿1 小时前
ArcGIS JS 基础教程(18):SceneLayer 场景图层
javascript