I wonder if PHP has any IIFE (Expression Execut Function Function Expression) equivalence like Javascript. Is it possible to write PHP Closure so that it works similarly to Javascript (call, dependency, injection, directive)?
(function(){ myModule = angular.module('myAngularApplication', []); }());
This expression is known above as an operative function statement (IIFE). Since the function definition will immediately call itself whenever a .js file is loaded. The main reason IIFE is effective is because we can run all the code right away without having to have global variables and functions. Now, when we do this, our controller creation will fail because we used a global variable to create the controller with the module. To work around this problem, use the getter angular.module function to associate the controller with the module. And while we are on it, why not put the controller in IIFE too.
(function () { var booksController = function ($scope) { $scope.message = "Hello from booksController"; } angular.module('myAngularApplication').controller('booksController', booksController); }());
Source: http://www.codeproject.com/Articles/995498/Angular-Tutorial-Part-Understanding-Modules-and Thank you.
source share