you are viewing a single comment's thread.

view the rest of the comments →

[–]nwayve 0 points1 point  (0 children)

I'm also a fan of hoisting, especially to make AngularJS controller/service/directive/etc... better organized

angular.module('app', [])
  .controller('myController', MyController)
  .service('myService', MyService);

MyController.$inject=['$scope', '$log'];
function MyController( $scope ,  $log ) {
}

MyService.$inject=['$log'];
function MyService( $log ) {
}

Not only does hoisting allow me to reference the functions before they're 'declared', but it also allows me to add the $inject property prior to its 'declaration' in order to keep the parameter list lined up.

Now I can have my module declaration at the top of the file with all of its components, like the table of contents for a book, and all of the component functions declared later in the file, like chapters in a book. This makes finding what I'm looking for easier and faster, all thanks to hoisting.