tags:

views:

129

answers:

2

As a "best practice" for front-end developers, is it bad to use the "control" property to reference back to the Javascript object?

Here's a link to the property in question: https://developer.mozilla.org/en/XUL/Property/control

I've seen a lot of Javascript functions that reference DOM elements using selectors and then perform DOM manipulation that way. But what if we started by traversing through the DOM tree and we have the DOM element first?

EDIT 1 Okay, it seems like there are some interest here but no contributions for some reason. This started as a conversation between me and my co-worker. He was concerned about circular references and possible cases of losing references... does that apply here? I thought as long as we don't call delete <javascript object> then we're fine.

EDIT 2 I found this: http://stackoverflow.com/questions/557533/jquery-methods-and-dom-properties

In my world right now, I'm using the Microsoft AJAX Library where we created multiple ScriptControls and put them on various pages; which in turn, (the ScriptControls) get "modified" by page's events and sometimes events of other ScriptControls. When pages need to do something with the DOM element, the Javascript would use the respective Javascript Object's methods.

However, it seems in JQuery (based on the other question), it's common to get the DOM element then use .get(0) to grab the JQuery object out of it (if it exists).

So I guess this is a witch hunt so far and there's still no right answer to my question :( I know I'm still lacking an example but I'm not sure how to approach this.

+1  A: 

I am not too sure what exactly you're referring to. Could you provide a simple code example? Otherwise, your question is a bit vague IMHO. I'll give it a shot anyways:

I do not understand why there would be any lost or circular references. The control attribute is just the id (string) of the "controlling" DOM Element, not a reference to the actual DOM Element. If you delete label.control it will no longer be associated with the other DOM Element.

CD Sanchez
Hi Daniel, sorry being vague on my question. I'll provide an example of what I mean soon.
Gary
A: 

Closing question as there does not seem to be a straight answer for this.

Gary