CoffeeScript 中未调用方法
Method is not called in CoffeeScript
我尝试用一个方法创建一个class,然后调用这个方法。但是永远不会执行 alert() 。为什么??
class Demo
constructor: (text) ->
@text = text
demo: ->
alert @text
d = new Demo "Hallo"
console.log d
d.demo
如果没有参数,则必须使用括号调用函数。
d.demo
应该是 d.demo()
.
我尝试用一个方法创建一个class,然后调用这个方法。但是永远不会执行 alert() 。为什么??
class Demo
constructor: (text) ->
@text = text
demo: ->
alert @text
d = new Demo "Hallo"
console.log d
d.demo
如果没有参数,则必须使用括号调用函数。
d.demo
应该是 d.demo()
.