[thelist] AJAX Tip

Matt Warden mwarden at gmail.com
Thu Apr 6 11:02:37 CDT 2006


> Sorry Matt, I wasn't talking about hooks in the markup, I said hooks in the
> code.
>
> E.g.  Whenever you use getElementById("id"), we're expecting an element with
> that ID.  So there's no maintenance difference.  Unless you're adding
> all your elements in JavaScript too!

That's actually what I figured you meant. I was just pointing out that
the "hook" is not a hook, but an id, which has nothing to do with JS
or CSS or anything else. If you only have one anchor in your entire
document, you could do: document.getElementsByTagName('a').item(0)
instead of document.getElementById('mylink'). It is simply a way of
navigating the document structure.

> I've said this before, but onlclick="return myFunc(this)" *isn't*
> mixing structure and behaviour, as long as the definition of myFunc is
> externalised.  However, I admit it *is* mixing markup and *code*.

what about this:

onclick="alert('hi');"

or maybe this?

onclick="return function() { return myFunc('foo'); };"

what about this?

onclick="return function() { if (this.value) return myFunc('foo');
else return false; };"

At what point is the definition no longer externalized?

onclick is a way of defining a behavior in response to an event, just
like defining myFunc() is defining behavior in response to that
function call.

> Doing getElementById('foo') is mixing structure and behaviour.

How is obtaining a reference to a dom element mixing structure and
behavior? When I say "structure", I'm talking about markup structure,
which is supposed to be a way of serializing a document tree. That's
why JS (and CSS) has no business within it.

> I'm starting to realise why we're having these discussions, as a web
> application developer I forget the majority of people do ordinary,
> content-based websites.  They can be totally different beasts.
> Absolutely, when using CMS for maintenance, any form of inline script
> is totally unrecommended.

I do strictly web application development, and I'm pretty sure
Christian does similar work. When systems start getting much more
complex is when separation like this becomes increasingly important
and has an increasing impact on maintenance and knowledge transfer
(e.g., during employee turnover) costs.

By the way, this is digressing into an argument we've had on this list
at least 3 times. There's more info in the archives.


--
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list