JavaScript is extremely flexible since objects are basically a map and can contain any number of key value pairs, where the value itself can be an object, and therefore you get nesting. Another interesting aspect of JavaScript is that the functions themselves are first class objects, so you can have a function as a value in a pair of key values.
To get something like jQuery, it becomes very simple. You start with a function (constructor or class function, if you want),
function myFunction() {
Since myfunction is a function and also an object, so you also attach key value pairs to it, which is what jQuery does. To verify that myFunction is also an object, do an instanceof check:
myFunction instanceof Function; // true myFunction instanceof Object; // true
Thus, we can add properties to a function, which can be a simple value or the functions themselves.
But if this is not your question, and you really want to know if you can literally call a function without using parentheses, then the answer is yes, you can, using the additions in ECMAScript 5th ed.
Here is an example of calling a function without using parentheses using Object.defineProperty and defining it as the recipient:
var o = {}; Object.defineProperty(o, "helloWorld", { get: function() { alert("hello world"); }, set: undefined }); o.helloWorld;
Try this example in Chrome or Safari or Firefox at night.
Anurag
source share