I've been using coffeescript on the front end for a few years now. And am familiar with class syntax looking something like this:
class MyClass
methodOne : ->
console.log "methodOne Called"
methodTwo : (arg, arrg) ->
console.log "methodTwo Called"
Recently I've been playing with node and the frappe boilerplate for web applications with coffeescript and node.
This script using CoffeeScript classes for routes with the following syntax:
class MyClass
@methodOne = ->
console.log "methodOne Called"
@methodTwo = (arg, arrg) ->
console.log "methodTwo Called"
The only usage difference I can note from my normal usage, is that the Routes.coffee file consumes the class directly rather than making a new
object. So:
MyClass.methodOne()
# vs
new MyClass().methodOne()
Now I've learned that the @methodOne
syntax is not using .prototype
while the other syntax does. But why would this make the usage fail?