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 小时前
链式法则解释上游梯度应用
开发语言·前端·javascript
爱隐身的官人3 小时前
爬虫基础学习-爬取网页项目(二)
前端·爬虫·python·学习
Jackson@ML3 小时前
使用字节旗下的TREA IDE快速开发Web应用程序
前端·ide·trea
烛阴6 小时前
解锁 TypeScript 的元编程魔法:从 `extends` 到 `infer` 的条件类型之旅
前端·javascript·typescript
前端开发爱好者6 小时前
弃用 ESLint + Prettier!快 35 倍的 AI 格式化神器!
前端·javascript·vue.js
wayhome在哪6 小时前
Cropper.js 轻松拿捏前端裁剪🤞
javascript·canvas·设计
&白帝&6 小时前
vue2和vue3的对比
javascript·vue.js·ecmascript
江东大都督周总6 小时前
rabbitmq集群
javascript·rabbitmq·ruby
vivi_and_qiao7 小时前
HTML的form表单
java·前端·html
一嘴一个橘子7 小时前
uniapp 顶部tab + 占满剩余高度的内容区域swiper
javascript·uni-app