[Javascript] AJAX app causing excessive browser memory usage

Rick Emery rick at emery.homelinux.net
Sat May 20 13:27:13 CDT 2006


Quoting Jonathan Buchanan <jonathan.buchanan at gmail.com>:

> Rick Emery wrote:
>> The short question: Why doesn't "this" in the handleXHRResponse()   
>> point to the object in which it resides (instance of xhrObj)?
>
> Here's a topic which should help answer this and your other questions:
>
> http://www.sitepoint.com/forums/showthread.php?t=364932
>
> Key points:
>
> "...in Javascript this refers to the calling context - not as you would
> expect from other languages, to the owner of the property. In
> Javacript, functions are variables like anything else so they can be
> passed around and referenced from multiple places."
>
> "...functions are not bound to objects. Objects are merely collections
> of functions. When you pass a function as a parameter ... you only pass
> the function - not the owner-object. Thus when the function is called,
> the context will not be your ownerobject."

That helps a lot, thanks. I was coming around to this understanding,  
since I got my hands on O'Reilly's "JavaScript: The Definitive Guide"  
last night, and it explains this pretty well.

The bottom line is that I assumed "this" in javascript was the same as  
"this" in other languages I have used. My mistake.

Thanks,
Rick
-- 
Rick Emery

"When once you have tasted flight, you will forever walk the Earth
  with your eyes turned skyward, for there you have been, and there
  you will always long to return"
                                               -- Leonardo Da Vinci




More information about the Javascript mailing list