jquery using this to access object context when inside callback
<p>Let us presume I have the following object defined:</p>

<pre><code>var myObj = function(){
     this.hello = "Hello,";
}

myObj.prototype.sayHello = function(){
     var persons = {"Jim", "Joe", "Doe","John"};
     $.each(persons, function(i, person){
       console.log(this.hello + person);
  }
}
</code></pre>

<p>Problem is that inside $.each this refers to person but I would like to access the obj property hello. </p>

<p>The only solution which i could find was declaring in sayHello function something like </p>

<blockquote>
  <p>var _this = this;</p>
</blockquote>

<p>and then in $.each i would use something like </p>

<pre><code>console.log(_this.hello + person);
</code></pre>

<p>But unfortunately, this is not very good code. Is there another way to resolve this problem elegantly ?</p>
