Skip to content

Blake lower #758

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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5502
}
36 changes: 34 additions & 2 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,40 @@

Each constructor function has unique properties and methods that are defined in their block comments below:
*/

/*
=== GameObject ===
* createdAt
* name
* dimensions (These represent the character's size in the video game)
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/
function GameObject(attributes) {
this.createdAt = attributes.createdAt;
this.name = attributes.name;
this.dimensions = attributes.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(attributes) {
GameObject.call(this, attributes)
this.healthPoints = attributes.healthPoints;
}

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

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

/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
Expand All @@ -32,7 +51,20 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(attributes) {
CharacterStats.call(this, attributes)
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.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: 49 additions & 11 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,64 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Implicit Binding: points to the obj. on which the function is called
* 2. Explicit Binding: We can explicitly tell the JS engine to set 'this' to point a certain value using call, apply, or bind
* 3. Global: is the global obj. in a non strict mode. & undefined in a strict mode
* 4. new Binding: Using the new keyword constructs a new obj. & 'this' points it.
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding

// code example for Window Binding (global)
console.log(this);
const allThis = function () {
console.log(this);
this.somethingg = "hiya";
}
allThis();
// Principle 2

// code example for Implicit Binding
const dog = {
name: 'sparky',
age: 3,
food: 'donuts',
activity: function (){
return `${this.name} loves to eat ${this.food}, since he has just turned ${this.age}`;
}
}
console.log(dog.activity());

// Principle 3

// Principle 3
// code example for New Binding

function Skateboards (color, model, year){
this.color = color;
this.model = model;
this.year = year;
}
var skateboads1 = new Skateboards('electric blue', 'zig zagger', 2011);
var skateboads2 = new Skateboards('bright purple', 'baker', 2010);
var skateboads3 = new Skateboards('lovely lilac', 'death wish', 2014);
console.log(skateboads1);
console.log(skateboads2);
console.log(skateboads3);
// Principle 4
// code example for Explicit Binding

const sponge ={
name: "Spongebob"
}
const star ={
name: "Patrick Star"
}
function whatsUp(passion1, passion2, passion3){
return `eeee!! my name is ${this.name} and the activities that bring me joy are ${passion1}, ${passion2} and ${passion3}`;
}
console.log(whatsUp.call(sponge, 'jellyfish', 'the Krusty Krab', 'Krabby Paddies'));

const starPassions = ['sleeping', 'eating', 'hanging with spongebob'];
console.log = (whatsUp.apply(star, starPassions));

// code example for Explicit Binding
const Spongebob = whatsUp.bind(sponge, 'jellyfish', 'the Krusty Krab', 'Krabby Paddies');
// console.log(Spongebob());