我已经在前端使用coffeescript几年了。而我所熟悉的类语法看起来像这样:Coffeescript类语法在节点中有何不同?
class MyClass
methodOne : ->
console.log "methodOne Called"
methodTwo : (arg, arrg) ->
console.log "methodTwo Called"
最近我一直在玩节点和frappe样板与CoffeeScript中和节点的Web应用程序。
使用CoffeeScript中类的语法如下路线这个脚本:
class MyClass
@methodOne = ->
console.log "methodOne Called"
@methodTwo = (arg, arrg) ->
console.log "methodTwo Called"
唯一的区别使用,我可以从我的正常使用请注意,是该文件Routes.coffee消费类,而不是直接制作new
对象。所以:
MyClass.methodOne()
# vs
new MyClass().methodOne()
现在我明白了,而其他的语法是否@methodOne
语法不使用.prototype
。但是,为什么这会导致使用失败?