简体   繁体   中英

Best practice declaring const

I have this declaration of a const. In angularExecutionService.cacheService I have a whole file of common methods in my app. The second part is really long and gets a little unreadable, but declaring a constant to solve a condition in a ternary and then assign that value to other constant results really overflowed to me.

Wich do you think is the best practice in this case? Declare all the second part in a const Declare the method in the second part of the ternary in a const Declare in a const only the argument in a const Keep the code like it is right now Something else...

const checkMainWindowGrid = checkGridIdByWindow
      ? false
      : executionNode.gridId ===
        this.angularExecutionService.cacheService.getGridIdByWindow(this.angularExecutionService.cacheService.getMainWindowName());

I have this declaration of a const. In angularExecutionService.cacheService I have a whole file of common methods in my app. The second part is really long and gets a little unreadable, but declaring a constant to solve a condition in a ternary and then assign that value to other constant results really overflowed to me.

Wich do you think is the best practice in this case? Declare all the second part in a const Declare the method in the second part of the ternary in a const Declare in a const only the argument in a const Keep the code like it is right now Something else...

const checkMainWindowGrid = checkGridIdByWindow
      ? false
      : executionNode.gridId ===
        this.angularExecutionService.cacheService.getGridIdByWindow(this.angularExecutionService.cacheService.getMainWindowName());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM