forked from bloominstituteoftechnology/JavaScript-IV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotes.txt
More file actions
104 lines (82 loc) · 2.19 KB
/
Copy pathNotes.txt
File metadata and controls
104 lines (82 loc) · 2.19 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function Fruit(fruitStuff){
this.type = fruitStuff.type;
this.geoArea = fruitStuff.geoArea;
// return this
}
Fruit.prototype.needsHeat = function(){
if(this.geoArea === 'tropical'){
return true;
}
return false;
}
function Apple(appleStuff){
// this = Apple {}
console.log("At the begining:", this)
Fruit.call(this, appleStuff);
//inherit
console.log("Halfway through:", this)
this.variety = appleStuff.variety;
this.color = appleStuff.color;
this.type = 'treefruit';
console.log("Right before return", this);
// return this
}
Apple.prototype = Object.create(Fruit.prototype)
Apple.prototype.isGoodInPie = function(){
return true;
}
const banana = new Fruit('Banana', 'tropical');
const apple1 = new Apple({variety: 'Honeycrisp', color: 'Orangered', type: 'Apple', geoArea: 'Northern Equitorial' });
// console.log("After the constructor: ", apple)
apple1.needsHeat()
apple1.isGoodInPie()
banana.needsHeat()
// <- ES6 Classes ->
class Fruit {
constructor(type, geoArea){
// this = {}
this.type = type;
this.geoArea = geoArea;
// return this
}
needsHeat(){
if(this.geoArea === 'tropical'){
return true;
}
return false;
}
isAFruit(){
return true;
}
}
class Apple extends Fruit {
// extends -> Apple.prototype = Object.create(Fruit.prototype);
constructor(variety, color){
// super calls the parents constructor passing in the context automatically
// super -> Fruit.call(this, 'Apple', 'Northern Equitorial');
super('Apple', 'Northern Equitorial')
this.variety = variety;
this.color = color;
this.type = 'treefruit';
}
isGoodInPie(){
return true;
}
}
class UMN extends Apple {
// extends -> UMN.prototype = Object.create(Apple.prototype);
constructor(variety, color){
super(variety, color)
// super -> Apple.call(this, variety, color);
}
createdAtUniveristyofMN(){
return true;
}
}
const banana = new Fruit('Banana', 'tropical');
console.log(banana.isAFruit());
const hcrisp = new UMN('Honeycrisp', 'Orangered');
const gsmith = new Apple('Granny Smith', 'Green');
console.log(hcrisp.isAFruit())
console.log(hcrisp.isGoodInPie())
console.log(hcrisp.createdAtUniveristyofMN())