RosettaCodeData/Task/Classes/Coco/classes.coco

16 lines
347 B
Plaintext

class Rectangle
# The constructor is defined as a bare function. This
# constructor accepts one argument and automatically assigns it
# to an instance variable.
(@width) ->
# Another instance variable.
length: 10
# A method.
area: ->
@width * @length
# Instantiate the class using the 'new' operator.
rect = new Rectangle 2