I was reading the source code of a library, which must remain anonymous, and I see that it's using an empty function to setup the namespace. It appears to be similar to the object literal notation (OLN) except that the base is a function.
Here's an example of the declaration.
/**
* Base namespace for FOO library
* @name FOO
* @namespace
*/
function FOO(){}
FOO.bar = 'bar const..';
FOO.fooFunc = function () { /* code */ };
FOO.Bar = function () { /* some constructor */ };
FOO.Bar.prototype.baz = function () { /* A prototype method on FOO.Bar */ };
...
As you can see, the FOO namespace is an empty function. Is there any point of declaring the namespace as an empty function? Is this a misuse of the OLN pattern? It looks like it may have been the start of a factory pattern. There's no prototype methods on the namespace (e.g. FOO.prototype.bar = ...
). Calling FOO()
clearly does nothing. Does anyone recognize this pattern?