Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
20 lines (14 sloc) 509 Bytes
class InvoiceForm
constructor: (@customer) ->
# Value of "this" might not be the InvoiceForm class
calculateTotal: =>
# do some fancy calculation
total = 10
alert "#{this.customer} your total is #{total}"
$ ->
invoice = new InvoiceForm("Acme Corporation")
invoice.calculateTotal()
$('#btnCalculate').click invoice.calculateTotal
# If you look at the JavaScript code generated, the
# code to make sure "this" is what you expect is
# more complicated than a simple _this.