mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
documentation waypoint
This commit is contained in:
parent
dcc70e5ab0
commit
c7fa9c320a
42 changed files with 1026 additions and 53 deletions
|
@ -136,13 +136,28 @@ 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."
|
||||
|
||||
# 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.
|
||||
# Inheritance and calling super.
|
||||
Animal: => .
|
||||
Animal.prototype.move: meters =>
|
||||
alert(this.name + " moved " + meters + "m.").
|
||||
|
||||
Snake: name => this.name: name.
|
||||
Snake extends Animal
|
||||
Snake.prototype.move: =>
|
||||
alert('Slithering...')
|
||||
super(5).
|
||||
|
||||
Horse: name => this.name: name.
|
||||
Horse extends Animal
|
||||
Horse.prototype.move: =>
|
||||
alert('Galloping...')
|
||||
super(45).
|
||||
|
||||
sam: new Snake("Sammy the Snake")
|
||||
tom: new Horse("Tommy the Horse")
|
||||
|
||||
sam.move()
|
||||
tom.move()
|
||||
|
||||
# Numbers.
|
||||
a_googol: 1e100
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue