この質問が何度か出されたことは知っていますが、どの回答にも混乱しています。なぜなら、coffeescript コードを特定の jquery コードにコンパイルする方法がわからないからです。
これは私がこれまでに持っているものです:
pluginName = 'tagbox'
states =
none: 0
typing: 1
altering: 2
defaults =
editing: true
tags: []
class Plugin
constructor: (@element, options) ->
@options = $.extend {}, defaults, options
@_defaults = defaults
@_states = states
@state = states.none
@_name = 'tagbox'
@currentTag = $("<div class='ui-individualtag'></div>")
# this is the public method I want
setCurrentTag: (tagText) ->
@currentTag.text(tagText)
$.fn[pluginName] = (options) ->
@each ->
if !$.data(this, "plugin_#{pluginName}")
$.data(@, "plugin_#{pluginName}", new Plugin(@, options))
)(jQuery, window, document)
そして、別のスクリプトで、次のように setCurrentTag メソッドにアクセスできるようにしたいと考えています。
tagbox = $('#tagbox').tagbox()
tagbox.setCurrentTag("hello world")
これがjqueryでコンパイルされるものを示すのに役立つかどうか教えてください。