zoukankan      html  css  js  c++  java
  • ES6 中 static 的this 问题 简单明了 备注清晰 谢谢欣赏

    class A {
        constructor(name,age) {
           this.name = name ;
           this.age = age;
        }
        say(){
        console.log(this)            //指向实例对象
        console.log(`I am ${this.name}`)
        }
        static sss(){
                console.log(this)          //指向类本身
          console.log(`I am ${this.age}`)    //I am undefined
          console.log(`I am ${this.name}`)     //I am A
        }
    }
    var a = new A('qwe',11);        
    a.say()
    A.sss()  //静态方法调用需要用类名.静态方法名

  • 相关阅读:
    POJ 1045
    POJ 1051
    POJ 1047
    POJ 1050
    POJ 1046
    POJ 1036
    POJ 1035
    POJ 1032
    【洛谷P1412】经营与开发
    【洛谷P3377】【模板】左偏树(可并堆)
  • 原文地址:https://www.cnblogs.com/CH-cnblogs/p/13386448.html
Copyright © 2011-2022 走看看