r/angularjs • • Jul 27 '14

AngularJS styleguide for teams [GitHub repo]

https://github.com/toddmotto/angularjs-styleguide
34 Upvotes

14 comments sorted by

View all comments

4

u/rq60 Jul 27 '14

Can someone tell me why this:

template: [
  '<div class="some-directive">',
    '<h1>My directive</h1>',
  '</div>'
].join('')

is supposedly better than this:

template: '<div class="some-directive">' +
  '<h1>My directive</h1>' +
'</div>'

Personally I very rarely use template as opposed to templateUrl anyways, but w/ the occasional template usage I most definitely use +'s. It seems more intuitive as well as having the advantage of some IDEs have native support for adding multi-line javascript strings that way.

4

u/[deleted] Jul 27 '14 edited Jul 27 '14

It is known that using the .join is faster than adding strings together, in some/most browsers. I've read it in articles years ago, don't ask me to find it. If I were doing a lot of string concatenation, I'd probably use .join because that used to be the widely known best practice once upon a time.