Understanding coding style in Angularjs

前端 未结 2 1476
孤城傲影
孤城傲影 2020-12-16 18:14

I came across different coding style using Angularjs and it made me think what the advantage and disadvantage of each coding style.

eg. Declaring of controllers:

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 19:02

    Style #1 means the controllers are defined outside of the module as globals, alright for small test projects but for any serious work, everything should be done using #2 or #3. The difference between #2 and #3 is #3 is minifiable as the $scope and $rootScope names in #2 will normally be optimised out, which causes the application to fail. #3 Stores these as strings which will not be minified out.

    If there's at least a possibility that you'll be minifying your code, go for #3. There's very little point in using #1 over #2 so I tend to avoid #1 altogether.

提交回复
热议问题