Created
October 2, 2013 09:37
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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