Initializing variables inline during declaration vs in the constructor in Angular with TS

后端 未结 2 1361
长发绾君心
长发绾君心 2021-01-02 03:43

I have been working for a while with Angular but can\'t find a definitive recommendation on :

Initializing member variables inline vs in the constructor

2条回答
  •  耶瑟儿~
    2021-01-02 04:18

    There is no difference basically, its just the convenience. Only difference for using constructor initialization is you can pass the value dynamically and then assign to it.

    constructor(visible) {
        this.isVisible = visible;  // <-- vs initialization in the constructor
    }
    

提交回复
热议问题