我有此类写入的CoffeeScript:无法访问方法在我的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()
行。相同的代码完全按预期工作如果我在Notification类中编写它(所有东西都被包装到一个IIFE中)。上述文件的加载顺序是:Notification.js然后SharerController.js
我在这里错过了什么?
1,2和3真的不是问题,因为我只是包含了我的代码的一些部分。但是我想出了命名空间,并且正在开展范围界定。 –