Sorry, cut and paste error there. Corrected:

function blah() {
 var blahThis = this;
 someExternalFunction( function() {
  blahThis.doSomething();
 });
}

Karl Rudd

On Sun, Feb 8, 2009 at 12:03 PM, Karl Rudd <karl.r...@gmail.com> wrote:
> Assign "this" to a local variable.
>
> function blah() {
>  var blahThis = this;
>  someExternalFunction( function() {
>   blahThis.doSomething();
>  }
> }
>
> Karl Rudd
>
> On Sun, Feb 8, 2009 at 9:28 AM, Alexander <kayuch...@gmail.com> wrote:
>>
>> Goodday!
>> Could anyone tell me how to save "this" context inside callback?
>> Here is simple example:
>>
>> var myClass = jQuery.Class.create({
>>        init: function(){
>>                this.value = "value";
>>
>>                // callback as argument:
>>                someExternalFunction( function() {
>>                                this.setValue(); // PROBLEM: "this" is not 
>> myClass pointer
>> anymore!
>>                        } );
>>        },
>>
>>        setValue: function () {
>>                this.title = "new value";
>>        }
>> });
>>
>

Reply via email to