Tuesday, May 10, 2011

OO HTML

I've been kicking around a thought in my head for a few days now, and I'm not sure where to go with it.  (Or if there even is anywhere to go with it.)  The idea struck me while I was at New England Code Camp this past Saturday, specifically in a session with MS-Joe on JavaScript in ASP.NET.  (Great speaker at workshops like this, by the way.  I'd love to attend more interactive stuff with this guy.)

He was talking about jQuery selectors and such, and someone in the audience asked, "So it uses CSS to select elements?"  Joe replied with a little explanation, but essentially said, "Yes, it uses CSS selectors."  Immediately I was compelled to raise my hand to clarify... "Well, it's not so much that it uses CSS selectors.  Think of it more that jQuery and CSS use the same selectors to identify elements in the DOM.  It doesn't really belong to either of them."  This prompted a very short discussion about how one can decorate elements with classes that have no CSS purpose and serve only for jQuery selection.  Joe said, "That's interesting, and I can't say I've ever used classes for non-CSS purposes before jQuery."

I didn't want to derail the session, so I kept my ongoing thoughts to my self where they've been stirring for a few days.  But ultimately, my thought was...
Can one effectively think of class specifications on HTML elements as analogous to interfaces on class implementations?
For some reason I'm fascinated by this question.  What are the implications, if any?  From the point of view of the selectors, it makes sense.  For example, if you want all of the "td" elements in the document, you can select them by their type.  Essentially, you're looking for a particular element implementation, "td."  Class specifications, on the other hand, are element-agnostic.  You can select by "myClass" and get all elements which have that class, regardless of their type.  Basically, all elements which implement the "myClass" interface regardless of the implementing type.

Does this even mean anything at all?  Is there any direction to take this?  I'm not sure.  Maybe I'm just mulling over the obvious, but for some reason the very concept of it intrigues and excites me.  Or maybe as I dive further into serious JavaScript application programming (I'm loving MooTools, by the way), someday this will make for an interesting and useful object-oriented approach to DOM manipulation.

It's just... interesting.

No comments:

Post a Comment