Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

typescript class static 如何同时支持静态访问和new出来的访问?

class A {
  public static q = 1;
  public static w (){
    return 'w'
  }
}

// 请问如何写让w方法和q支持下面两种写法呢

A.w()
A.q

(new A()).w()
(new A()).q

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
class A {
    public static q = 1;
    public static w() {
        return 'w';
    }

    public get q() {
        return A.q;
    }
    public w() {
        return A.w();
    }
}

这样?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...