私はこの指定されたjqueryコードにcoffeescriptコードをコンパイルする方法がわからないので、この質問は何度か尋ねられました。プラグインの外からのjquery/coffeescriptプラグインへのアクセス方法
これは私がこれまで持っているものです。
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でコンパイルされていることを示すのに役立ちます。
tagbox = $('#tagbox').tagbox()
はjQueryオブジェクトになり、それがsetCurrentTag
メソッドを持っていません。
@RicardoTomasi:jQuery-UIスタイルの '$(x).tagbox( 'setCurrentTag'、 'hello world')もあります。それは私が見た標準的なアプローチに最も近いものであり、連鎖を維持しながら名前空間を汚染するのを避けています。 –
@muistooshortはい、しかし、彼はもう一方を求めました。それはどちらかの方法で混乱です:) –