Skip to content

Instantly share code, notes, and snippets.

@himynameisdave
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save himynameisdave/0729fa9376dcd9235d05 to your computer and use it in GitHub Desktop.

Select an option

Save himynameisdave/0729fa9376dcd9235d05 to your computer and use it in GitHub Desktop.
.bind(this) For Dummies [BROKEN]
//[BROKEN]
var IceCream = {
flavors: [ 'vanilla', 'chocolate', 'bubblegum' ],
newFlavor: 'banana',
addNewFlavor: function( ){
var safeToAdd = true;
// check if we've added it already
this.flavors.forEach(function(flavor){
if(flavor === this.newFlavor) // <- this throws an error
safeToAdd = false;
});
if(safeToAdd)
this.flavors.push(this.newFlavor);
}
}
IceCream.addNewFlavor();
@himynameisdave
Copy link
Copy Markdown
Author

@ericperez Yes, there was a lot of better options I overlooked as I was trying to keep the article just about the .bind() method. I am in the process of editing it so that the whole array part isn't even in there.

I appreciate the feedback!

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