Hi Rudi,
On Apr 20, 2:45 am, Rudi Hausmann <rudi...@nospam.comwrote:
Hi!
I create HTML pages on the server side. I want to extend DIV elements
with more information.
E.g.:
<DIV id="Joe" />
Now I want Joe to have an age for example and access it using:
$('joe').age = 20;
I don't do this but I did see an example in a JavaScript book about
adding what they called a "backing object" to an HTML. The backing
object would have extra information and functions associated with the
object. This would be something like
$('joe').backingObject = {/*...*/};
In that book they also discussed the need to clean these backing off
the object on page unload for memory leak reasons. The problem with
this is JavaScript books are very often wrong in very substantial
ways. I did ask about this practice on comp.lang.javascript much like
you but didn't have any response.
If you do the following you do get the circular memory leak in IE
because the object the HTML object has a reference to the function and
the function has a reference to the object in it's scope chain.
var joe = $('joe');
joe.myFn = function(){};
If you do the following I am not sure if the function has the HTML
object in the function's scope chain. My guess is yes.
$('joe').myFn = function(){};
Hopefully someone else will elaborate on extending HTML objects and
the memory leak issues.
Peter