方法未在CoffeeScript中调用
我尝试用一个方法创建一个类,然后调用这个方法。但是alert()永远不会执行。为什么方法未在CoffeeScript中调用,coffeescript,Coffeescript,我尝试用一个方法创建一个类,然后调用这个方法。但是alert()永远不会执行。为什么 class Demo constructor: (text) -> @text = text demo: -> alert @text d = new Demo "Hallo" console.log d d.demo 如果没有参数,则必须使用参数调用函数 d.demo应该是d.demo()您看过文档了吗?前几段介绍了这一点:
class Demo
constructor: (text) ->
@text = text
demo: ->
alert @text
d = new Demo "Hallo"
console.log d
d.demo
如果没有参数,则必须使用参数调用函数
d.demo
应该是d.demo()
您看过文档了吗?前几段介绍了这一点: