I understand about self invoking anonymous functions like so:
(function () {
//...
})();
and that most of the time they are used for creating closures and abstracting variables in frameworks. However I've also seen sources in different sites that declare anonymous functions but they do not invoke them. I'm curious as to how those are used. Are they invoked when the script is loaded? Note that in the sources tab they don't look like .js files. Instead they have a name like so:
extensions::utils
, or extensions::Event
etc.
They look like they're part of some kind of framework/library? I'm not sure. For example the extensions::Event
has this code inside:
(function($Object, $Function, privates, cls, superclass) {'use strict';
function Event() {
var privateObj = $Object.create(cls.prototype);
$Function.apply(cls, privateObj, arguments);
privateObj.wrapper = this;
privates(this).impl = privateObj;
};
if (superclass) {
Event.prototype = Object.create(superclass.prototype);
}
return Event;
}) //<-Self invocation missing.
As you can see this is just declared but not used. The only thing I can think of is that this anonymous function is actually assigned to a variable called Event
and is part of the extensions
object or something?