Home › Forums › JavaScript › Cache Your jQuery objects In a jQuery object itself › Re: Cache Your jQuery objects In a jQuery object itself
I think you both made valid points. I don’t feel safe adding my properties and methods to an object created by another library, so i store jQuery elements like so:
var menu = {
$: $(‘#menu’),
prop: value
};
menu.$.addClass(‘super-special’);
Interestingly enough though I saw memory leaks mentioned somewhere and a quest to learn more lead me here. I’m fairly certain that none of the code above would cause memory leaks my my definition (a memory leak keeps growing IMO, not simple be maintained across the life of a page) some articles though, stated storing DOM objects to variables inside closers = the most common cause for leaks.