This may turn out to be a simple question with a very complex answer, or something very simple which I have just missed completely, but, in libraries like Prototype and jQuery etc., how can the $ global variable be an object that contains functions, for example:
$.ajax.get(…);
and also a function itself, like:
$("…");
Any help, even a pointer to a more explanatory Web site would be brilliant, I’m just intrigued!
For example, if I created a function ($), that contained a child object (ajax) like:
var $ = function() {
this.ajax = {};
return this;
};
I could access the ajax object like $().ajax, but not like $.ajax, how do you get them both?
In JavaScript, functions are Objects, and Objects may have properties, so it’s just another wonderful part of the language!