Writing a jquery plugin in coffeescript - how to get “(function($)” and “(jQuery)”?

后端 未结 8 1167
温柔的废话
温柔的废话 2020-12-13 12:55

I am writing a jquery plugin in coffeescript but am not sure how to get the function wrapper part right.

My coffeescript starts with this:

$.fn.exten         


        
8条回答
  •  忘掉有多难
    2020-12-13 13:37

    Unless you're using the --bare flag in the compiler, the

    $ = jQuery
    

    solution is best. If you are, then with the new do keyword, you can write

    do ($ = jQuery) ->
       # plugin code...
    

    thus creating the desired scope while avoiding a mess o' parentheses.

提交回复
热议问题