I use a similar pattern: it is particularly useful for storing nodes
which may be disconnected and later re-connected to the DOM; or for
'models' which have multiple 'views' (i.e., a list view and a detail
view).
In fact, I usually also store the complementary relationship in the
node pointed-to by the jQuery object (not in the jQuery object
itself. In your example, that would be:
function Sprite(dom, html) {
this.$dom = $(dom);
this.$dom.data('sprite', this);
}
oliver
On Feb 14, 3:42 pm, weepy <[email protected]> wrote:
> A pattern I use quite often within my JS classes is to store relevant
> DOM nodes as a property on the class.
>
> e.g.
>
> function Sprite(dom, html) {
> this.dom = dom;
>
> }
>
> Sometimes it would be convenient to store the jQuery instance bound to
> this node, e.g. :
>
> function Sprite(dom, html) {
> this.$dom = $(dom);
>
> }
>
> I've always avoided doing this as I was concerned about memory, GC and
> storing a 'whole' jQuery obect for each reference. However, I realise
> that this is entirely superstitious and was wondering if anyone knew
> whether it was good/bad for GC/memory/style.
>
> Thanks
>
> weepy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---