errorhandler errorhandler - 6 days ago 6
Javascript Question

Calling a function in javascript without parentheses

Is there a way in JavaScript to call a function with out parentheses?

For example in jQuery:

$('#wrap').text("asdf");
will work and so will
$.ajax(ajaxOptions);


Update - More Info

I'm mapping a function (class) to
window.$
that has a set of functions I want to be able to call with or without parentheses. like jQuery.

Update 2

Here's a code example:

function Test(asdf) {
this.test = function(testVar) { return testVar + ' asdf'; }
}


and I map
Test()
to
$
:

window.$ = new Test();


I have to call the function (class) like this:

$('asfd').test('ASDF');


but I want to be able to call it like this:

$.test('asdf');


Sorry for all the confusion.... I'm really tired

Answer

You can try something like this

var test = {
    method1 : function(bar) {
        // do stuff here
        alert(bar);
    },
    method2 : function(bar) {
        // do stuff here
        alert(bar);
    }
};

test.method1("foo");
test.method2("fooo");
Comments