Skip to content

Commit 5caf5d7

Browse files
author
Christopher Blum
committed
Added example
1 parent 9526401 commit 5caf5d7

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.textile

+25-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,28 @@ h1. Class.create([superclass][, methods...])
99

1010
If a subclass overrides an instance method declared in a superclass, the subclass's method can still access the original method. To do so, declare the subclass's method as normal, but insert $super as the first argument. This makes $super available as a method for use within the function.
1111

12-
*For details, see the ["inheritance tutorial on the Prototype website":http://prototypejs.org/learn/class-inheritance].*
12+
*For details, see the ["inheritance tutorial on the Prototype website":http://prototypejs.org/learn/class-inheritance].*
13+
14+
h2. Example
15+
16+
bc.. // properties are directly passed to `create` method
17+
var Person = Class.create({
18+
initialize: function(name) {
19+
this.name = name;
20+
},
21+
say: function(message) {
22+
return this.name + ': ' + message;
23+
}
24+
});
25+
26+
// when subclassing, specify the class you want to inherit from
27+
var Pirate = Class.create(Person, {
28+
// redefine the speak method
29+
say: function($super, message) {
30+
return $super(message) + ', yarr!';
31+
}
32+
});
33+
34+
var john = new Pirate('Long John');
35+
john.say('ahoy matey');
36+
// -> "Long John: ahoy matey, yarr!"

0 commit comments

Comments
 (0)