<commit_before>---
layout: post
title:  "What is 'this'?"
date:   2016-03-02 22:47:43 -0800
categories: jekyll update
---
Completing the pre-coursework curriculum has been a daunting challenge, especially with the pressing cohort start date. Working full time really takes nearly <em>all</em> time and it’s been difficult squeezing in spurts of productive learning. Before finding my way to Telegraph Academy, I had tried my hand at many tutorial courses, katas, and attended a few of Hack Reactor’s [Algorithm Study Groups](http://www.meetup.com/hackreactor/events/228753374/), but the first sprint and assessment required deeper comfort with the material right off the bat.

The hands-on emphasis using live professional tools, languages, and technologies sped my trajectory enormously. It’s clear that we’ll hit the ground running on Day 1 – beyond the obvious familiarity with github, the command line, and basic Javascript syntax and patterns, we've been required to show growing comfort with more general Computer Science concepts.

Working through the material, I immediately came across difficulties– a strong grasp of scopes, 'this', and recursion is just the start! While many of the skills and concepts we hope to master are applicable in countless other coding languages, we must overcome the nuances of Javascript in particular. Two early projects require us to rewrite the [Underscore.js](http://underscorejs.org/) library, and create a simple Twitter clone using [jQuery](https://jquery.com/).

These two Sprints ultimately required me to spend time Googling the use of arguments and the means to share information between functions. I quickly found my solution depended totally on the methods [.call()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call) and [.apply()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply), the standard tools for this problem. To be able to use these nifty functions, we have to understand the keyword [‘this’](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this), and I was surprised how murky its explanations can be.

Although it was clear that ‘this’ “mostly behaves as a parameter.” The specifics are a bit more complex. The discussion provided by the Hack Reactor material was definitely the clearest, but they made sure to explain what it ISN’T before revealing the extra simple answer for what it IS.

Consider the example below:

{% highlight javascript %}

var someObject = {
  someFunction: function(a, b){
    console.log(this);
  }
};

var aSecondObject = {
  aContainedMethod: someObject.someFunction
};

{% endhighlight %}

When we’re referring to ‘this’, we’re NOT referring to the following:

-	The function object ‘this’ appears within (e.g. someObject{})
-	If ‘this’ is part a method, or within another object, <em>that</em> object 'this' is within (e.g. someFunction())
-	A ‘new instance’ of the function where ‘this’ appears within  (e.g. someFunction() at run time)
-	An object that might happen to have the 'this's containing function as property (e.g. aSecondObject())

To understand ‘this’ we need to appreciate the fact that it’s <em>ONLY</em> bound to a value, it only means anything, when the function runs at call time. Consider the following, while passing some objects to work with:

{% highlight javascript %}

var someObject = {
  someFunction: function(a, b){
    console.log(this);
  }
};

var aSecondObject = {
  aContainedMethod: someObject.someFunction
};

var manzana = {}, naranja = {}, platano = {};

someObject.someFunction(naranja, platano);

{% endhighlight %}

'this' is bound <em>only</em> at the point at which it's called.

{% highlight javascript %}

someObject.someFunction(naranja, platano);

{% endhighlight %}

Finally, ‘this’ is tied to the object <em>"directly to the left of the dot (or brackets) at invocation"</em> and 'this' is bound to someObject{}
<commit_msg>Add code comment, clarify some<commit_after>---
layout: post
title:  "What is 'this'?"
date:   2016-03-02 22:47:43 -0800
categories: jekyll update
---
Completing the pre-coursework curriculum has been a daunting challenge, especially with the pressing cohort start date. Working full time really takes nearly <em>all</em> time and it’s been difficult squeezing in spurts of productive learning. Before finding my way to Telegraph Academy, I had tried my hand at many tutorial courses, katas, and attended a few of Hack Reactor’s [Algorithm Study Groups](http://www.meetup.com/hackreactor/events/228753374/), but the first sprint and assessment required deeper comfort with the material right off the bat. More time commitment is necessary.

The hands-on emphasis using live professional tools, languages, and technologies sped my trajectory enormously. It’s clear that we’ll hit the ground running on Day 1 – beyond the obvious familiarity with github, the command line, and basic Javascript syntax and patterns, we've been required to show growing comfort with more general Computer Science concepts.

Working through the material, I immediately came across difficulties– a strong grasp of scopes, 'this', and recursion is just the start! While many of the skills and concepts we hope to master are applicable in countless other coding languages, we must overcome the nuances of Javascript in particular. Two early projects require us to rewrite the [Underscore.js](http://underscorejs.org/) library, and create a simple Twitter clone using [jQuery](https://jquery.com/).

These two Sprints ultimately required me to spend time Googling the use of arguments and the means to share information between functions. I quickly found my solution depended totally on the methods [.call()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call) and [.apply()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply), the standard tools for this problem. To be able to use these nifty functions, we have to understand the keyword [‘this’](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this), and I was surprised how murky its explanations can be.

Although it was clear that ‘this’ “mostly behaves as a parameter.” The specifics are a bit more complex. The discussion provided by the Hack Reactor material was definitely the clearest, but they made sure to explain what it ISN’T before revealing the extra simple answer for what it IS.

Consider the example below:

{% highlight javascript %}

// Some initial object
var someObject = {
  // Contains a method which accepts two arguments as parameters
  someFunction: function(a, b){
    // Logs value bound to 'this' to the console
    console.log(this);
  }
};

var aSecondObject = {
  // An example method in an external second object holding the function containing 'this'
  aContainedMethod: someObject.someFunction
};

{% endhighlight %}

When we’re referring to ‘this’, we’re NOT referring to the following:

-	The function object ‘this’ appears within (e.g. someObject{})
-	If ‘this’ is part a method, or within another object, <em>that</em> object 'this' is within (e.g. someFunction())
-	A ‘new instance’ of the function where ‘this’ appears within  (e.g. someFunction() at run time)
-	An object that might happen to have the 'this's containing function as property (e.g. aSecondObject())

To understand ‘this’ we need to appreciate the fact that it’s <em>ONLY</em> bound to a value, it only means anything, when the function runs at call time. Consider the following, while passing some objects to work with:

{% highlight javascript %}

var someObject = {
  someFunction: function(a, b){
    console.log(this);
  }
};

var aSecondObject = {
  aContainedMethod: someObject.someFunction
};

// Some objects to work with
var manzana = {}, naranja = {}, platano = {};

// Calling someFunction() using the two objects
someObject.someFunction(naranja, platano);

{% endhighlight %}

'this' is bound <em>only</em> at the point at which it's called.

{% highlight javascript %}

someObject.someFunction(naranja, platano);

{% endhighlight %}

Finally, ‘this’ is tied to the object <em>"directly to the left of the dot (or brackets) at invocation"</em> and 'this' is bound to someObject{}

{'fraction_non_alphanumeric': 0.0859234369374775, 'fraction_numerical': 0.00672026881075243, 'mean_word_length': 4.665533650577839, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1350256', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2149, 'n_words': 1063}