2

Is this a good or a bad practise structuring the code this way and injecting the dependencies like below? I like to separate all my code in closures so that I structure them the way below - As far as I remember it is a good practise because using strict mode in a closure instead of in the root scope won't brake other library that may not be using it at all. Correct me if thats wrong too.

Given the following example code of my approach:

/**
 * @this {angular.module}
 * @param {jQuery} $
 * @param {undefined} undefined
 */
(function ($, undefined) {
    'use strict';

    /**
     * @param {$routeProvider} $routeProvider
     */
    this.config(function ($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'views/main.html',
                controller: 'MainCtrl',
                controllerAs: 'main'
            })
            .when('/about', {
                templateUrl: 'views/about.html',
                controller: 'AboutCtrl',
                controllerAs: 'about'
            })
            .otherwise({
                redirectTo: '/'
            });
    });

}).call(window.myApp = window.myApp || createApp(), jQuery);

Side question for up-vote (I think it is related as I'm injecting myApp as "this" but please let me know if we are strict and this should be a separate one): How to type hint "this"?

haxpanel
  • 4,402
  • 4
  • 43
  • 71

0 Answers0