-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest
More file actions
57 lines (45 loc) · 1.23 KB
/
test
File metadata and controls
57 lines (45 loc) · 1.23 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
var foodType = {fish: 0, bones: 1}
function Animal()
{
var foodTypeForEating;
this.Eat = function(foodType) {foodTypeForEating = foodType;}
this.SaySomething = function(typicalFoodOfAnimal)
{
if (typeof(foodTypeForEating) == "undefined" || foodTypeForEating == null)
{
console.log("Nothing to eat...");
}
else
{
if (foodTypeForEating == typicalFoodOfAnimal)
{
console.log("It's very tasty...");
}
else
{
console.log("I will not eat it...");
}
}
}
}
var Cat = function()
{
var typicalFoodOfCats = foodType.fish;
this.__proto__ = new Animal();
this.SaySomething = function() {this.__proto__.SaySomething(typicalFoodOfCats);}
}
var Dog = function()
{
var typicalFoodOfDogs = foodType.bones;
this.__proto__ = new Animal();
this.SaySomething = function() {this.__proto__.SaySomething(typicalFoodOfDogs);}
}
var cat = new Cat();
var dog = new Dog();
cat.Eat(foodType.fish);
dog.Eat(foodType.fish);
cat.SaySomething();
dog.SaySomething();
var animal = new Animal();
animal.Eat(foodType.fish)
animal.SaySomething(foodType.fish);