errorhandler errorhandler - 1 year ago 119
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:

will work and so will

Update - More Info

I'm mapping a function (class) to
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

window.$ = new Test();

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


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


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

Answer Source

You can try something like this

var test = {
    method1 : function(bar) {
        // do stuff here
    method2 : function(bar) {
        // do stuff here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download