私はこのクラスをCoffeeScriptで書いています:
Notification.js.coffee
class Notification
display: ->
@dom.show()
constructor: (header, messages) ->
@render(header, messages)
基本的に、関数コードのロジックは、render()
HTMLをDOMに挿入し(ただし非表示)、display()
単純shows
にDOM要素をメソッド化することです。今、私はこのクラスとは別のクラスを持っており、上記のクラスを利用しようとしています。
SharerController.js.coffee
class SharerController
post_story: ->
# some user action posting something in the app
notification = new Notification('Header', ['This story has been posted.', 'You can post more. Would you like to?'])
notification.display()
残念ながら、何らかの理由で-私は得る
TypeError: 'undefined' is not a function (evaluating 'notification.display()')
私が行う上記の行にnotification.display()
。通知クラス(すべてがIIFEにラップされる)内に記述した場合、同じコードが完全に期待どおりに機能します。上記のファイルのロード順序は、Notification.js、次にSharerController.jsです。
私はここで何が欠けていますか?