Reputation: 5821
After reading about self invoking functions I decided to take it for a spin, wondering why this example code does not invoke after it has loaded.
var App = App || {};
(function() {
'use strict';
App.MainUtility = {
sayHello: function() {
alert('Hello from the main utility');
}
};
return App.MainUtility;
})();
Is there a chance that I am not understanding something properly?
Upvotes: 1
Views: 56
Reputation: 754525
In this case your self executing function has done 2 things
MainUtility
on App
At no point was it invoked hence nothing is expected to be displayed. You can display it though by adding the following line in place of return
App.MainUtility.sayHello();
Upvotes: 2