-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimals.js
More file actions
58 lines (37 loc) · 1.22 KB
/
Animals.js
File metadata and controls
58 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var Animal, Cat, Dog, fido, willow,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Animal = (function() {
function Animal(petName, animal) {
this.petName = petName;
this.animal = animal;
}
Animal.prototype.speak = function(say) {
return alert("" + this.petName + " the " + this.animal + " says: " + say);
};
return Animal;
})();
Dog = (function(_super) {
__extends(Dog, _super);
function Dog(petName) {
Dog.__super__.constructor.call(this, petName, 'dog');
}
Dog.prototype.speak = function() {
return Dog.__super__.speak.call(this, 'woof');
};
return Dog;
})(Animal);
Cat = (function(_super) {
__extends(Cat, _super);
function Cat(petName) {
Cat.__super__.constructor.call(this, petName, 'cat');
}
Cat.prototype.speak = function() {
return Cat.__super__.speak.call(this, 'meow');
};
return Cat;
})(Animal);
willow = new Cat('Willow');
willow.speak();
fido = new Dog('Fido');
fido.speak();