[jQuery] Re: Loosing access to 'this' objects in callback method!

2007-06-26 Thread Glenn Knowles
Hi Nate, Thanks again for your reply. You've supplied some good resources and explanations, and I'm getting a better understanding. However, each time I 'think' I've got it, I come across a situation that just proves I don't. It's going to be a struggle, but I'm determined to get to the 'p

[jQuery] Re: Loosing access to 'this' objects in callback method!

2007-06-24 Thread Ⓙⓐⓚⓔ
Nate, beautiful! the tricky: obj2.run.call(instance); // now obj2.run is called, it's own 'this' points to obj instead of obj2 shows that this is not always what is seems to be! call and apply are both ways to override this. Because they are tricky... I like to isolate call and apply to the bo

[jQuery] Re: Loosing access to 'this' objects in callback method!

2007-06-24 Thread Nate Cavanaugh
Hi Glenn, Closures are a pretty tough concept to fully explain. In this case, I should have just said to use an "anonymous function", as it would probably lead to less confusion. Here is a great online resource about closures that really helped me a lot: http://www.hunlock.com/blogs/Closing_The_B

[jQuery] Re: Loosing access to 'this' objects in callback method!

2007-06-24 Thread Glenn Knowles
Hi Nate, First of all, thank you very much for taking the time to respond. It's greatly appreciated. I had to modify your solution slightly, in that the ajax.complete callback passes two parameters which I need, so I changed the code to... var instance = this; $.ajax( { type: "

[jQuery] Re: Loosing access to 'this' objects in callback method!

2007-06-23 Thread Nate Cavanaugh
Hi Glenn, Keeping scope is definitely one of the more frustrating aspects of Javascript sometimes. What's happening is that you're running the ajax call, and the complete method is a method of the object that you're passing into the ajax handler. So this now points to the object containing the