Monday 24 March 2008

Convenience Syntax in Examples

This is a "meta" post, e.g., it's about the blog itself.

In many of my posts, I give code examples to illustrate a point. To avoid cluttering the examples up with browser-specific stuff, I'm using a couple of calls from the Prototype library.

Actually, right now, just the one: Event.observe(). This function hooks up an event handler in a way that is consistent across browsers, even Internet Explorer, which is good because IE doesn't support the standard addEventListener() function, and its own attachEvent() function behaves slightly differently (within the handler, "this" is the global object, like in old DOM0 handlers; whereas with addEventListener it's the element you're hooking the event to). Prototype's Event.observe() ensures that "this" is always the element, even on IE, and also does some housekeeping to try to mitigate an IE bug where it tends to leak memory if you use closures as event handlers (which is incredibly common).

If I use more Prototype stuff, I'll list it here as well, but this is only about trying to keep the examples simple and clear, not about using Prototype or any other specific library...

3 comments:

Qasim Khan said...

I was more than happy to uncover this great site. I need to thank you for your time due to this fantastic read!! Do My College Homework I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.

basiapacocha said...

This will change your life forever ...I tried many wholesale dildo toys and nothing comes close to my ROSÉ sure I named him rosè with a fancy è ... Babyyy if you haven't felt pure pleasure or looking for a toy that can take your Sexual feeling to another stage..that is the toy for you .. Put RoSè in place and let him do his job .. BE warned that Rosé is highly addicted and can go away you dehydrated..

Payday Cash said...

Santander empowers homeowners with their santander home improvement loans, ensuring a smooth and stress-free process for enhancing your living environment.