Skip to content

Commit fb4c08f

Browse files
committed
Finished this.js
1 parent 468e20c commit fb4c08f

3 files changed

Lines changed: 76 additions & 22 deletions

File tree

.idea/workspace.xml

Lines changed: 46 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assignments/prototypes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* dimensions
1515
* destroy() // prototype method -> returns the string: 'Object was removed from the game.'
1616
*/
17+
GameObject.prototype = Object.create(CharacterStats.prototype);
1718
function GameObject(gameAttributes){
1819
this.createdAt = gameAttributes.createdAt;
1920
this.dimensions = gameAttributes.dimensions;
2021
GameObject.prototype.destroy = function(){
21-
return 'Object was removed from the game. ';
22+
return `${this.name} was removed from the game.`;
2223
}
2324
}
2425

assignments/this.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
11
/* The for principles of "this";
22
* in your own words. explain the four principle for the "this" keyword below.
33
*
4-
* 1.
5-
* 2.
6-
* 3.
7-
* 4.
4+
* 1. Window/Global when the function this is invoked without any other definitions of it.
5+
* 2. Implicit Binding: Invoking a function with this such as this.function
6+
* 3. Explicit Binding: when methods like .call(), .apply() and bind() are used on a function
7+
* 4. New Binding: this will require us to build _proto_ tree in order access different variables from constructors
88
*
99
* write out a code example of each explanation above
1010
*/
1111

1212
// Principle 1
1313

1414
// code example for Window Binding
15-
15+
console.log(this);
1616
// Principle 2
1717

1818
// code example for Implicit Binding
1919

20+
const SomeObject = function (){
21+
this.name = 'someObjName';
22+
};
23+
24+
SomeObject.prototype.someFunction = function (anotherName) {
25+
console.log(`${this.name} is ${anotherName}`);
26+
};
27+
28+
let csgo = new SomeObject();
29+
csgo.someFunction('Counter-Strike Global Offensive');
2030
// Principle 3
2131

2232
// code example for New Binding
23-
33+
Humanoid.prototype = Object.call(CharacterStats.prototype);
34+
function Humanoid (humanAttributes) {
35+
this.faction = humanAttributes.faction;
36+
}
37+
38+
CharacterStats.prototype = Object.call(Humanoid.prototype)
39+
function CharacterStats(charAttributes) {
40+
this.hp = charAttributes.hp;
41+
}
42+
// this will need to be called in order to access variables throughout different constructors
2443
// Principle 4
2544

26-
// code example for Explicit Binding
45+
// code example for Explicit Binding
46+
let person = {name: 'Oleks', countryFrom: ' from Ukraine'};
47+
SomeObject.prototype.someFunction.call(person, person.countryFrom);

0 commit comments

Comments
 (0)