In Javascript functions are first-class objects. In particular, they are objects.
var greet = function(name) {console.log("Hello, " + name + "!"); };
greet.lang = "English";
Is legal. Then the following are both valid:
greet("Alice"); // prints Hello, Alice!
console.log(greet.lang); // prints English
I don't think it's accurate to call $(...)
a constructor. In Javascript the line between constructor and function is blurred, but usually I would say a constructor is used with new
, and, by convention, starts with a Capital letter. $
is simply an object, and in particular one that is a function, so may be called, and has other properties that may be accessed.
I also wouldn't call $
, or in my example greet
, a namespace. You may be thinking of the package syntax in Java where com.mycompany.util.StringFunctions
would have the package/namespace com.mycompany.util
, or in C++ where this might be written as MyCompany::Util::StringFunctions
. Javascript doesn't quite have this concept, but in more or less any OO language it can be simulated with objects, as above. I would say $
just feels like it's a namespace because it's a rather huge library, but it's a huge library that is implemented as one object that is also a function, with many properties.