On Dec 21, 7:25 am, raysaun <[email protected]> wrote:
> I'm fairly new to JS with no formal training, but I try my best to be
> conscientious...
>
> I notice that in our code base lots of data gets shoved into the
> browser's DOM. Is that a good idea? For example, a component might
> perform an AJAX call, get a set of data from the server, and then
> stick the result directly into the DOM (e.g.
> company_namespace.component.content.result_1,
> company_namespace.component.content.result_2, etc...) for later
> access. It feels kind of dirty to me.

Not sure what you mean by "shoved into the browser's DOM". If you mean
added as properties of DOM elements, then yes, that's a bad idea. It
would be much better to store it some other way, say a native object.


> It seems like you'd want to use
> a closure of some sort that has an underlying private array with
> accessor functions to add or retrieve information.

Closures are good for private members (functions, objects, data) but
aren't always the best or only solution.


> Are my concerns valid?

Yes.

> Is there a compelling reason to NOT stuff junk
> into the DOM?

Because the DOM is a bunch of host objects that are only loosely
specified by the W3C. While they are generally very similar across
browser, they can have very hard to find gotchas. Just don't do it.

However, I'm not sure that's what you're doing. Storing data in native
objects and array is what they are designed for. You may create some
"namespace" struture using an object, but you could also just create
global variables with long names:

  company_namespace.component.content.result_1

becomes

  companyNamespace_component_content_result_1


I'm not recommending that, just saying it's roughly equivalent.


> If the answer has been oft-covered or is obvious please feel free to
> point to a reference. Since I've discovered this mailing list I've
> been "living on the end of a fire hose" (which is ok, you know...).

It's been covered in clj, seach there. Here's some threads:

"pseudo-namespacing in JavaScript"
<URL:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/494e1757fa51fe3f/5331d91fe28a20da?q=object+namespace+group:comp.lang.javascript+author:peter+author:michaux#5331d91fe28a20da
>

"Initializing a global namespace object"
<URL:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/106d9ad6a2277642/d387e6533aa4e8cb?q=object+namespace+group:comp.lang.javascript#d387e6533aa4e8cb
>


--
Rob

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to