Skip to content

Commit 1d7d765

Browse files
authored
Merge pull request #1 from astillo/alexander-stillo
adding files.
2 parents 33d1564 + 66eee25 commit 1d7d765

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

assignments/prototypes.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,49 @@
4040
*/
4141

4242
// Test you work by un-commenting these 3 objects and the list of console logs below:
43+
function GameObject(att){
44+
this.createdAt = att.createdAt;
45+
this.name = att.name;
46+
this.dimensions = att.dimensions;
47+
}
48+
GameObject.prototype.destroy = function(){
49+
console.log(`${this.name} was removed from the game`)
50+
}
51+
52+
53+
function CharacterStats(att){
54+
GameObject.call(this, att)
55+
this.healthPoints = att.healthPoints;
56+
57+
}
58+
CharacterStats.prototype = Object.create(GameObject.prototype)
59+
CharacterStats.prototype.takeDamage = function () {
60+
console.log(`${this.name} took damage`)
61+
}
62+
63+
64+
function Humanoid(att){
65+
CharacterStats.call(this, att)
66+
CharacterStats.prototype.takeDamage.call(this, att)
67+
GameObject.call(this, att)
68+
this.team = att.team;
69+
this.weapons = att.weapons;
70+
this.language = att.language;
71+
72+
}
73+
Humanoid.prototype = Object.create(CharacterStats.prototype)
74+
//Humanoid.prototype = Object.create(CharacterStats.prototype.takeDamage)
75+
//Humanoid.prototype = Object.create(GameObject.prototype)
76+
Humanoid.prototype.greet = function () {
77+
console.log(`${this.name} offers a greeting in ${this.language}`)
78+
}
79+
80+
81+
82+
83+
84+
4385

44-
/*
4586
const mage = new Humanoid({
4687
createdAt: new Date(),
4788
dimensions: {
@@ -102,7 +143,7 @@
102143
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
103144
console.log(mage.takeDamage()); // Bruce took damage.
104145
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
105-
*/
146+
106147

107148
// Stretch task:
108149
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.

assignments/this.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@
1010
*/
1111

1212
// Principle 1
13-
13+
function birthday(when){
14+
console.log(when);
15+
return this;
16+
}
17+
birthday("082997");
1418
// code example for Window Binding
1519

1620
// Principle 2
21+
const getBirthday ={
22+
birthday: '082997',
23+
birth: function(time){
24+
console.log(`${birthday} is mine yours is ${time}`)
25+
console.log(this)
26+
}
27+
}
28+
getBirthday.birth('20')
1729

1830
// code example for Implicit Binding
1931

0 commit comments

Comments
 (0)