Skip to content

Instantly share code, notes, and snippets.

@pellekrogholt
Created October 2, 2013 09:37
Show Gist options
  • Save pellekrogholt/6791298 to your computer and use it in GitHub Desktop.
Save pellekrogholt/6791298 to your computer and use it in GitHub Desktop.
window example so its possible to call outside the coffee wrapper - and a function call within the - simple modified version of the one in "CoffeeScript Application Development"
# we have window to make the class accessible outside the coffee wrapper
# e.g.:
# > train = new Train(35)
# > train.funcwithinclass()
class window.Train
constructor: (numCars, type="diesel") ->
@type = type
@numCars = numCars
@load = 0
@capacity = numCars * 100
describe: ->
"A #{@type} train with #{@numCars} cars." +
" Current filled: #{@load}/#{@capacity} tons."
funcwithinclass: ->
@describe()
train = new Train(35)
console.log train.describe()
console.log train.funcwithinclass()
train2 = new Train 20, "steam"
console.log train2.describe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment