从ts编译代码看js数据成员

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/themagickeyjianan/article/details/87870748

1)1.ts

class  A {
    static m: number = 1;
    private n: number;
    setA(){
        this.n = 11;
    }

    getA(){
        console.log(this.n);
    }
}

let a = new A();
a.setA();
a.getA();
console.log(A.m);

2)经过tsc 1.ts编译后得到的js

var A = /** @class */ (function () {
    function A() {
    }
    A.prototype.setA = function () {
        this.n = 11;
    };
    A.prototype.getA = function () {
        console.log(this.n);
    };
    A.m = 1;
    return A;
}());
var a = new A();
a.setA();
a.getA();
console.log(A.m);

可见A.m就相当于静态数据。

猜你喜欢

转载自blog.csdn.net/themagickeyjianan/article/details/87870748