When using classes in Coffeescript, I’ve stumbled upon a major problem, let me illustrate
class Bet
constructor: () ->
placeBet: ->
$('#chips > div').bind 'click', ->
amount = $(this).attr 'id'
pile = $(this)
switch amount
when "ten" then this.bet pile, amount #This line causes a problem
bet: (pile, amount) ->
alert 'betting!'
The call to this.bet above generates the following error:
Uncaught TypeError: Object # has no method ‘bet’
So, currently the instance method of my class is not being called,
How can I correctly call the bet method of my class without it colliding with the jQuery selector’s this (Which is what I suppose is happening now)?
Thank you very much in advance!
Try this: