Skip to content

Commit

Permalink
Add OOP example
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Mar 20, 2012
1 parent 0cba23c commit 6bcfe7e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test-objects.can
@@ -0,0 +1,24 @@
print = global.print

Rectangle = {}
Rectangle.getArea = (self) {
return self.w * self.h
}
Rectangle.initialize = (self, w, h) {
self.w = w
self.h = h
}

Square = new Rectangle
Square.initialize = (self, s) {
self.w = s
self.h = s
}

rect = new Rectangle
rect:initialize(3, 5)
print("Rectangle 3x5 =", rect:getArea())

square = new Square
square:initialize(4)
print("Square 4x4 =", square:getArea())

0 comments on commit 6bcfe7e

Please sign in to comment.