added the ability to super()

This commit is contained in:
Jeremy Ashkenas
2009-12-17 09:07:42 -05:00
parent 01ecae2c55
commit cd0091c045
6 changed files with 856 additions and 774 deletions

View File

@@ -128,4 +128,12 @@ three_to_six: zero_to_nine[3, 6]
# Multiline strings with inner quotes.
story: "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim ad."
aliquam erat volutpat. Ut wisi enim ad."
# Calling super from an overridden method.
Greeter: => . # Create the parent object.
Greeter.prototype.hello: name => alert('Hello ' + name). # Define a "hello" method.
Exclaimer: name => this.name: name. # Create the child object.
Exclaimer.prototype: new Greeter() # Set the child to inherit from the parent.
Exclaimer.prototype.hello: => super(this.name + "!"). # The child's "hello" calls the parent's via "super".
(new Exclaimer('Bob')).hello() # Run it.