[TS] Class Properties Public, Private and Read Only Modifiers

In the constructor, we want to set the prop to readonly, you need to do like this:

class Superhero {
   
    readonly name: string

    constructor(
        name: string,
        editor: string,
        createdYear: number
    ) {

            name = this.name;
    }
}

 

posted @ 2018-02-05 19:37  Zhentiw  阅读(472)  评论(0编辑  收藏  举报