Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8ee12e1

Browse files
Jashele TJashele T
Jashele T
authored and
Jashele T
committed
refactored prototype-refactor .js
1 parent f4cd074 commit 8ee12e1

File tree

2 files changed

+45
-48
lines changed

2 files changed

+45
-48
lines changed

‎assignments/lambda-classes.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
// CODE here for your Lambda Classes
2+
3+
class Person {
4+
constructor(attributes) {
5+
6+
}
7+
}

‎assignments/prototype-refactor.js‎

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Prototype Refactor
2929

3030

3131
// === GameObject ===
32+
3233
// function GameObject(GameObj) {
3334
// this.createdAt = GameObj.createdAt;
3435
// this.name = GameObj.name;
@@ -45,32 +46,41 @@ Prototype Refactor
4546
this.dimensions = GameObj.dimensions;
4647
}
4748

49+
50+
4851
// GameObject.prototype.destroy = function() {
4952
// return `${this.name} was removed from the game.`; // prototype method that returns: `${this.name} was removed from the game.`
5053
// }
5154

55+
56+
5257
// Prototype Refactored:
5358
destroy() {
5459
return `${this.name} was removed from the game.`;
5560
}
5661
}
62+
63+
5764

5865

5966
// === CharacterStats ===
67+
6068
// function CharacterStats(charAttrs) {
61-
// GameObject.call(this, charAttrs);
62-
// this.healthPoints = charAttrs.healthPoints;
69+
// GameObject.call(this, charAttrs);
70+
// this.healthPoints = charAttrs.healthPoints;
6371
// };
6472

6573

74+
6675
// CharacterStats Refactored:
6776

6877
class CharacterStats extends GameObject {
6978
constructor(charAttrs){
70-
super(GameObj);
79+
super(charAttrs);
7180
this.healthPoints = charAttrs.healthPoints;
7281
}
7382

83+
7484

7585
// CharacterStats.prototype = Object.create(GameObject.prototype);
7686

@@ -91,34 +101,30 @@ Prototype Refactor
91101

92102

93103

94-
95104
// === Humanoid (Having an appearance or character resembling that of a human.) ===
96105

97106
// function Humanoid(HumanoidAttr) {
98-
// CharacterStats.call(this, HumanoidAttr);
99-
// this.team = HumanoidAttr.team;
100-
101-
// this.weapons = HumanoidAttr.weapons;
102-
103-
// this.language = HumanoidAttr.language;
104-
107+
// CharacterStats.call(this, HumanoidAttr);
108+
// this.team = HumanoidAttr.team;
109+
// this.weapons = HumanoidAttr.weapons;
110+
// this.language = HumanoidAttr.language;
105111
// };
106112

107113

108114

109115
// Humanoid Refactored:
110116

111-
class Humanoid extends GameObj {
117+
class Humanoid extends CharacterStats {
112118
constructor(HumanoidAttr) {
113-
super(GameObj);
119+
super(HumanoidAttr);
114120
this.team = HumanoidAttr.team;
115121
this.weapons = HumanoidAttr.weapons;
116122
this.language = HumanoidAttr.language;
117123
}
118124

119125

120126
// Humanoid.prototype = Object.create(CharacterStats.prototype);
121-
// // should inherit takeDamage() from CharacterStats
127+
// should inherit takeDamage() from CharacterStats
122128

123129

124130
// Humanoid.prototype.greet = function() {
@@ -143,56 +149,41 @@ Prototype Refactor
143149

144150
// Test you work by un-commenting these 3 objects and the list of console logs below:
145151

146-
152+
153+
147154
const mage = new Humanoid({
148-
createdAt: new Date(),
149-
dimensions: {
150-
length: 2,
151-
width: 1,
152-
height: 1,
153-
},
154-
healthPoints: 5,
155-
name: 'Bruce',
156-
team: 'Mage Guild',
157-
weapons: [
158-
'Staff of Shamalama',
159-
],
160-
language: 'Common Tongue',
161-
});
155+
createdAt: new Date(),
156+
dimensions: {length: 2, width: 1, height: 1, },
157+
healthPoints: 5,
158+
name: 'Bruce',
159+
team: 'Mage Guild',
160+
weapons: ['Staff of Shamalama',],
161+
language: 'Common Tongue',
162+
})
163+
164+
162165

163166
const swordsman = new Humanoid({
164167
createdAt: new Date(),
165-
dimensions: {
166-
length: 2,
167-
width: 2,
168-
height: 2,
169-
},
168+
dimensions: {length: 2, width: 2, height: 2, },
170169
healthPoints: 15,
171170
name: 'Sir Mustachio',
172171
team: 'The Round Table',
173-
weapons: [
174-
'Giant Sword',
175-
'Shield',
176-
],
172+
weapons: ['Giant Sword', 'Shield',],
177173
language: 'Common Tongue',
178-
});
174+
})
175+
179176

180177
const archer = new Humanoid({
181178
createdAt: new Date(),
182-
dimensions: {
183-
length: 1,
184-
width: 2,
185-
height: 4,
186-
},
179+
dimensions: {length: 1, width: 2, height: 4, },
187180
healthPoints: 10,
188181
name: 'Lilith',
189182
team: 'Forest Kingdom',
190-
weapons: [
191-
'Bow',
192-
'Dagger',
193-
],
183+
weapons: ['Bow', 'Dagger', ],
194184
language: 'Elvish',
195185
});
186+
196187

197188
console.log(mage.createdAt); // Today's date
198189
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /