Day 13: Review of ‘this’ at JavaScriptisSexy.com

My review of .bind(), .call() and .this() led to JavaScript is Sexy, which recommended as prior reading, it’s article on understanding the use of the this keyword in functions. I took up their recommendation.

  • Just finished the first ‘Sticky’ point or most confusing/tricky instances where this won’t operate as might be expected. And I actually understood it completely, which is a testament to the article because other tutorials/resources really weren’t as helpful.
  • My main takeaway right now is that this inside a function called as a method to an object will refer to the object. The problem in passing that object.method as an argument in another function or object.method is that this will refer to the new object that is ultimately invoking the function holding this. But you fix this by binding the old/previous object to this using the .bind() method on the object.method that currently holds this. So instead of newObject.method(oldObject.method), you write newObject.method(oldObject.method.bind(oldObject)).
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s