Wrapping code in anonymous closures - good practice?


Hi there!

In an Ionic project we are wrapping code from each js file in an anonymous closure like this:

(function () {
    'use strict';

            .controller('HomeController', HomeController);

    /* @ngInject */
    function HomeController(ENV) {
        var vm = this;

        // vm variables
        vm.environment = ENV.name;

        // vm functions
        vm.createGroup = createGroup;
        vm.openMyProfileModal = openMyProfileModal;



        function _activate() {


        function createGroup() {


        function openMyProfileModal() {


I’d like to ask if this is being seen by the community as good practice.


This is considered general good angular practice. I’m assuming the people who wrote this app followed the johnpapa style guide…which is a very good guide. Here is the exact section addressing your question: https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#iife


Thanks @rlouie for your reply, in the meantime, after some more reading, I am absolutely convinced that this is a good practice.