A property that is read-only outside of the class, but read-write for class members

For future readers, We can use getter to allow reading property outside class, but restrict edit.

class Test {
    private x_ = new Uint8Array([0, 1, 2]);

    get x() {
        return this.x_;
    }
}
let test = new Test();
console.log(test.x) //Can read
test.x = 1; //Error: Cannot assign to 'x' because it is a read-only property.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)