There is an anonymous function taking three parameters (root
, ns
, factory
) which is immediately invoked.
root
takes the value of`window.
ns
takes the value of 'detectZoom'
factory
takes the value of callback function (also anonymous)
The explanation:
(function (root, ns, factory) {
// the body of the anonymous function
} (window, 'detectZoom', function() {
// the body of the 'factory' callback
}));
To break it apart, how to get to this code in four steps:
1.
// Anonymous function.
(function (root, ns, factory) {/* body */});
2.
// Anonynmous function, immediately invoked
(function (root, ns, factory) {/* body */})(); // parentheses mean it's invoked
3.
// Callback as a separate argument
var cbk = function () {};
(function (root, ns, factory) {/* body */})(window, 'detectZoom', cbk);
4.
// Callback as an anonymous function
(function (root, ns, factory) {/* body */})(window, 'detectZoom', function () {});
You could rewrite your code to be more verbose:
var outer = function (root, ns, factory) {
// the body
};
var callback = function () {
// the body
};
outer(window, 'detectZoom', callback);