Skip to content

Commit 654c9ad

Browse files
committed
completed prototypal-inheritance
1 parent 15f9f89 commit 654c9ad

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

topics/about_prototypal_inheritance.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ Mammal.prototype = {
1616

1717
test("defining a 'class'", function() {
1818
var eric = new Mammal("Eric");
19-
equal(__, eric.sayHi(), 'what will Eric say?');
19+
equal("Hello, my name is Eric", eric.sayHi(), 'what will Eric say?');
2020
});
2121

2222
// add another function to the Mammal 'type' that uses the sayHi function
2323
Mammal.prototype.favouriteSaying = function() {
24-
return this.name + "'s favourite saying is " + this.sayHi();
24+
return this.name + "'s favourite saying is " + this.sayHi();
2525
}
2626

2727
test("more functions", function() {
2828
var bobby = new Mammal("Bobby");
29-
equal(__, bobby.favouriteSaying(), "what is Bobby's favourite saying?");
29+
equal("Bobby's favourite saying is \"Hello, my name is Bobby\"", bobby.favouriteSaying(), "what is Bobby's favourite saying?");
3030
});
3131

3232
test("calling functions added to a prototype after an object was created", function() {
@@ -36,26 +36,26 @@ test("calling functions added to a prototype after an object was created", funct
3636
};
3737
// the following statement asks the paul object to call a function that was added
3838
// to the Mammal prototype after paul was constructed.
39-
equal(__, paul.numberOfLettersInName(), "how long is Paul's name?");
39+
equal(undefined, paul.numberOfLettersInName(), "how long is Paul's name?");
4040
});
4141

42-
// helper function for inheritance.
42+
// helper function for inheritance.
4343
// From https://developer.mozilla.org/en/JavaScript/Guide/Inheritance_Revisited
44-
function extend(child, supertype){
45-
child.prototype = supertype.prototype;
46-
}
44+
function extend(child, supertype){
45+
child.prototype = supertype.prototype;
46+
}
4747

4848
// "Subclass" Mammal
4949
function Bat(name, wingspan) {
5050
Mammal.call(this, name);
5151
this.wingspan = wingspan;
52-
}
52+
}
5353

5454
// configure inheritance
5555
extend(Bat, Mammal);
5656

5757
test("Inheritance", function() {
5858
var lenny = new Bat("Lenny", "1.5m");
59-
equal(__, lenny.sayHi(), "what does Lenny say?");
60-
equal(__, lenny.wingspan, "what is Lenny's wingspan?");
59+
equal("Hello, my name is Lenny", lenny.sayHi(), "what does Lenny say?");
60+
equal("1.5m", lenny.wingspan, "what is Lenny's wingspan?");
6161
});

0 commit comments

Comments
 (0)