Skip to content

finished this #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,34 @@
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/

function GameObject(attribute){
this.createdAt = attribute.createdAt;
this.name = attribute.name;
this.dimensions = attribute.dimensions;
}

GameObject.prototype.destroy = function () {
return `${this.name} was removed from the game`
};

/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/

function CharacterStats(attribute) {
GameObject.call(this,attribute);
this.healthPoints = attribute.healthPoints;
}

CharacterStats.prototype = Object.create(GameObject.prototype);

CharacterStats.prototype.takeDamage = function(){
return `${this.name} took damage`
}

/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -33,6 +54,19 @@
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(attribute) {
CharacterStats.call(this, attribute);
this.team = attribute.team;
this.weapons = attribute.weapons;
this.language = attribute.language;
}

Humanoid.prototype = Object.create(CharacterStats.prototype)

Humanoid.prototype.greet = function() {
return '${this.name} offers a greeting in ${this.language}'
}

/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
Expand Down
60 changes: 51 additions & 9 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Window or Global binding. This means if used on the global scope (not inside a function or method) then it will be pointed at the Global scope.
* 2. Implicit binding. When you call a function using a dot, then the this applies to the function mentioned on the left side of that dot. That's the function we'll be using.
* 3. Explicit binding. When you call a function and use .call, .apply, or bind. You "explicitly" tell "this" to use the function mentioned in the argument.
* 4. New Biding. When a constructor function is used. "This" is used in the object to refer to a specific item and then you can return that in the constructor function.
*
* write out a code example of each explanation above
*/
Expand All @@ -13,14 +13,56 @@

// code example for Window Binding

// Principle 2
funtion animalName(type) {
console.log(this);
return type;
}
animalName('panther');


// Principle 2
// code example for Implicit Binding
const myMonster = {
name: 'Dracula',
hobby: 'suck blood',
bat: '🦇',
vampire: function(){
console.log(`Hi, I'm ${this.name} and I like to ${this.hobby}. At night, I fly in the form of a ${this.bat}`);
}
}

myMonster.vampire();

// // Principle 3
// // code example for New Binding

function Travel(country) {
this.place = country;
}

let planningTravel = new Travel('Egypt');
console.log(`When I graduate Lambda, the first place I plan to visit is ${planningTravel.place}!`);


// // Principle 4

// // code example for Explicit Binding

// Principle 3
function myMusic(){
console.log(`I love music! My favorite singer is ${this.name}. Their style is ${this.style} and my favorite song is ${this.song}!`);
}

// code example for New Binding
let smEnt = {
name: 'EXO',
style: 'Kpop',
song: 'Call me Baby'
}

// Principle 4
let rnb = {
name: 'Lizzo',
style: 'Soul,R&B,rap',
song: 'Soulmate'
}

// code example for Explicit Binding
myMusic.call(smEnt);
myMusic.call(rnb);