Calling a function in JavaScript without parentheses

前端 未结 7 1640
醉梦人生
醉梦人生 2020-12-09 07:27

Is there a way in JavaScript to call a function without parentheses?

For example in jQuery:

$(\'#wrap\').text(\"asdf\"); will work and so will <

相关标签:
7条回答
  • 2020-12-09 07:58

    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");
    
    0 讨论(0)
提交回复
热议问题