Can I call a Javascript function from a coffeescript file?

后端 未结 1 1757
遇见更好的自我
遇见更好的自我 2021-01-28 05:35

I\'m trying to call a javascript function from a Coffeescript file, for my $(document).ready() and it\'s never getting called.

The function I want to call c

相关标签:
1条回答
  • 2021-01-28 05:47

    This doesn't do what you think it does:

    $ -> ready
    

    In JavaScript that is:

    $(function() {
        return ready;
    });
    

    Your problem is that just ready is simply a reference to the function, it is not a function call like it would be in Ruby. You'd have to say ready() to call the function, the function calling parentheses are only optional when you're calling a function with arguments: f x and f(x) are the same but f and f() are different.

    I think you want to say:

    $ -> ready()
    

    or even:

    $ ready # same as $(ready)
    
    0 讨论(0)
提交回复
热议问题