(function(){
...code...
})()
IIFE's Actually Do Make Sense
Why to Use It
A Great Example
snippet of html:
<div ng-controller="MyCtrl as vm"> <select ng-options="vm.someOptions" ng-model="vm.someModel" ng-change="vm.myFunction()"></select> </div>
(function(){ angular.module('myapp').controller('MyCtrl', MyCtrl); function MyCtrl() { var vm = this; vm.someModel; vm.someOptions = []; // set these vm.myFunction = myFunction; activate(); function activate() { myFunction(); } function myFunction() { // TODO: will be called onchange and // when controller starts } } })();