This article describes the method of defining global objects in JavaScript. Share it for your reference, as follows:
!function (factory) { factory(window['Hi'] = { __a: function () { ('Hi.__a'); }, __b: function () { ('Hi.__b'); }, __c: function () { ('Hi.__c'); } }); }(function (Hi) { if (typeof Hi === undefined) { Hi = {}; } (Hi, 'appName', { get: function () { return 'this is app name.'; } }) }); ();//this is app name. Hi.__b();//Hi.__b
Pass the object (Hi) definition function as a parameter (factory) to the immediate execution function by executing the function immediately
!function (factory) { }();
In the immediate execution function, the object to be defined is passed as a parameter to the argument function of the immediate execution function.
The same object definition can be implemented as follows:
var myObj = myObj || {}; (function (myObj) { myObj.__a = function () { ('myObj.__a'); }; = 'this is '; })(myObj); ();//this is myObj.__a();//myObj.__a
These definition methods are relatively independent and can be saved and used as functional modules of the Party Capital.
Plugin writing similar to Jquery.
For more information about JavaScript, readers who are interested in reading this site's special topic:JavaScript object-oriented tutorial》、《Summary of JavaScript search algorithm skills》、《Summary of JavaScript data structure and algorithm techniques》、《Summary of json operation skills in JavaScript》、《Summary of JavaScript Errors and Debugging Skills"and"Summary of JavaScript mathematical operations usage》
I hope this article will be helpful to everyone's JavaScript programming.