Skip to content

Wilfred Morgan: Javascript III Project - #1

Open
wmemorgan wants to merge 7 commits into
masterfrom
wilfred-morgan
Open

wmemorgan wants to merge 7 commits into
masterfrom
wilfred-morgan

Conversation

@wmemorgan

@wmemorgan wmemorgan commented Jan 23, 2019 •

Copy link
Copy Markdown
Owner

Javascript III Project Submission

Project Objectives

MVP

  • Use the this.js file to traverse through a few this problems.
  • Follow the prototypes.js instructions closely to create the beginnings of what could be an awesome JavaScript game.

Stretch Goals

  • Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
  • Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0;
  • Create two new objects, one a villain and one a hero and fight it out with methods!

Summary

The Javascript concepts that I have been taught so far have been extremely helpful in demystifying why certain things are done a certain way. (Example: what's under the hood for .map(),.filter(),.reduce()).

My only concern is that not enough practice time is being allotted before having to complete the sprint challenge, especially with the abbreviated week.

Blocks

  • Coming up with the actual examples that demonstrate the different binding principles without just copying what was taught during the lecture and Q&A.

Breakthroughs

  • In creating an example of explicit binding I was able to incorporate a number of concepts that have been taught so far:

    • Instantiated a new object from a constructor to use for the example.
    • Used the .map() method to dynamically display the items in a list with proper formatting.
    • Use of the ternary operator to create a list that is grammatically correct
  • Creating and using constructors and prototype functions has clicked for me.


Additional Notes

Object oriented programming is a major topic. Although I see the value of using this approach for easily creating multiple objects that share the same attributes I also see how easy it would be to create spaghetti code through multiple nested inherited object creation. I would like to learn good design patterns that would mitigate this occurrence.


This change is Reviewable

@wmemorgan
wmemorgan requested a review from JoeBugajski January 24, 2019 02:44

@JoeBugajski JoeBugajski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding work, as usual! I'm nominating you for the Nobel Prize for coming up with a good example of explicit binding.

Comment thread assignments/this.js

// Principle 4
// code example for Explicit Binding

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the best example of explicit binding I've seen. It's difficult for me to come up with a good reason to use it.

@wmemorgan wmemorgan Jan 24, 2019 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Joe!

To answer your comment:

It's difficult for me to come up with a good reason to use it.

This particular code allows you to combine an object and an array and dynamically iterate through the array (instead of listing item1, item2, item3, etc).

An example I could think of for using this code in real life for creating a mail merge of customer information into a marketing form letter. So if I take my code from Exercise bloominstituteoftechnology#4 and extend it for this example we've got something like this....

function Customer (name, package) {
  this.name = name,
  this.package = package
  this.greeting = function () {
    return `Hello ${this.name}`
  }
}
//Creating an object from the Customer constructor

const joe = new Customer('Joe', premium) //Premium Service Customer
//Create an array of a list of services
const premiumPackage = ['ESPN', 'Disney Channel', 'HBO', 'Cinemax', 'Showtime', 'Starz']

const wilfred = new Customer('Wilfred', basic) //Basic Service Customer
//Create an array of a list of services
const basicPackage = ['ESPN', 'Disney Channel']

// Automatically generate new customer welcome letter
function welcomeLetter (list) {
  return `${this.greeting()}, we see you've signed up for our ${this.package} channels: ${list.map((item, index) => index !== list.length-1 ?' '+ item: ' and ' + item)}.`
}
// Explicity bind the object and array to the introduce function using the .call() method
console.log(welcomeLetter.call(joe, premiumPackage))
console.log(welcomeLetter.call(wilfred, basicPackage))
`

Being able to do things like that will make you a hero with the marketing folks and management. Haha!

There's more you can do with this code but this shows the possible value of using explicit binding.

Comment thread assignments/prototypes.js

Hero.prototype = Object.create(Humanoid.prototype)
Hero.prototype.battleCry = function () {
return `${this.affliation}es will save the world, YO JOE!!!`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell if this is an Easter Egg for me or a GI Joe reference! This is probably the best game I've yet seen for this project.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is a GI Joe, reference. I purposely mixed genres to see if anyone would notice. Haha!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants