On 1/28/11, Nicholas C. Zakas <[email protected]> wrote: [...]
> > In it, I mention the issue of JS libraries. I’ll repeat what I said there: > if you’re comfortable betting your application on a single JS library, then > go ahead and let it leak through the abstraction. For instance at Yahoo, we > know we’re going to use YUI, so it’s okay for the modules to access YUI > directly. If I were working for another company, I might choose to abstract > away some common pieces just in case I decided to swap JS libraries. The > main goal is, of course, so you never have to rewrite the modules regardless > of what changes occur in the rest of the stack. But once again, if you are > comfortable tying your application to jQuery, then by all means, use it > directly in the modules. > I don't agree with following feeling for program design. FOr other things, sure, and place value in fun, but not for the cold hard design of programs (its not fun). > I kick off JS execution as soon as my modules are loaded. That might occur > before DOMContentLoaded, before load, or after load, depending on how the > resources are being loaded. The important thing is that the order of module > initialization shouldn’t matter (that’s the purpose of loose coupling). You > should, in theory, be able to start one module now and one two minutes from > now, and have nothing of consequence occur. > I generally prefer using event delegation, so that when the user interacts with something, that it is intercepted higher up and dealt with at that time. > I’ve used this on two major projects (My Yahoo! and the Yahoo! homepage), so > I’m fairly comfortable recommending it for any single-page site. I’ve not > tried it on a multi-page site, so I can’t really speak to that. > I agree with the advice of loose coupling but I'm not sure how you've applied them in those examples. They're not good examples of front end engineering overall. The HTML isn't even valid; never has been: <http://validator.w3.org/check?uri=http%3A%2F%2Fwww.yahoo.com%2F&charset=%28detect+automatically%29&doctype=Inline&group=0> I know it might sounds like red herring, but when I look at the example, the first thing I see is invalid HTML -- that can cause problems because browsers don't have standard error correction mechanisms. Sure HTML 5 is trying to codify it but what about IE8 and such? I've worked on bad pages too and at some point it can help pay the rent. So while I agree conceptually with the type of advice I read, I don't agree (or don't see where) that those apps are good examples. If you have a specific case of code reuse there that can be explained, that might be helpful. I'm not looking that hard, TBH. Live's short. And I;d be out playing if I wasn't all banged up now :-(. -- Garrett -- 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]
