Repository navigation
Conversation
Created constructors for Villain and Hero affliations Add character backgrounds for Villain and Hero
Add attack methods for both groups Extend background story Add battle sequence
JoeBugajski
left a comment
There was a problem hiding this comment.
Outstanding work, as usual! I'm nominating you for the Nobel Prize for coming up with a good example of explicit binding.
|
|
||
| // Principle 4 | ||
| // code example for Explicit Binding | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| Hero.prototype = Object.create(Humanoid.prototype) | ||
| Hero.prototype.battleCry = function () { | ||
| return `${this.affliation}es will save the world, YO JOE!!!` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes that is a GI Joe, reference. I purposely mixed genres to see if anyone would notice. Haha!
Javascript III Project Submission
Project Objectives
MVP
thisproblems.Stretch Goals
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
Breakthroughs
In creating an example of explicit binding I was able to incorporate a number of concepts that have been taught so far:
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