Oracle Magazine Special offer for AjaxImpact.com Visitors!! Subscribe to Oracle Magazine for Free!
AJAX IMPACT


TUTORIALS
Metaprogramming JavaScript Tutorial - Part 1
03/30/2007 By Adam McCrea


Last week, I gave a presentation at the Columbus Ruby Brigade meeting about metaprogramming JavaScript. Although I posted that presentation here, the slides were short on text, so I thought it would be more helpful if I wrote a series of tutorials to discuss these concepts. Also, I want to take my example a bit further with more extensions and refactoring.

But before we dive into what metaprogramming is, why it is important, and how we can bring it to life in JavaScript, let’s start with an example that we can build on throughout the tutorial: Say we’ve got a really basic form with select boxes for country and state, and we have a requirement to only show the state when the selected country is “United States”.



This code works just fine, and there is certainly nothing wrong with it for such a simple requirement. Unfortunately, things get hairy as requirements change. Let’s see how our code scales when we want to do the following:

  • add province field

  • show province when country is “Canada”

  • show state when country is “United States”

  • show Brutus when state is “Ohio” or “Michigan”

       Read Full Tutorial ...

     Rate this Ajax Tutorials
     Rating: 8.7 out of 115 votes cast

    AJAX NEWS
    04/25/2006 ThickBox - Show html pages as well as images in Lightbox
    04/24/2006 AgileGallery - AJAX Photo gallery for Picasa
    04/24/2006 TeamSlide: Online Ajax-powered Web Presentations
    04/23/2006 Google Blogoscoped Chat Released as Open Source
    04/18/2006 Windows Live Academic Beta is now live !
    04/18/2006 Ask Cheggers - Ajax powered chat bot


    INDUSTRY NEWS
    05/19/2006 Ajax grabs center stage at JavaOne, By Tony Baer
    05/15/2006 Oracle to boost AJAX, Java , By Paul Krill
    05/13/2006 Open AJAX Group Drafts Development Plans, By Stacy Cowley
    05/13/2006 AJAX Powers Interactive Marketing ASP, By AjaxWorld News Desk
    05/12/2006 AJAX Experts Tackle Security, Other Issues , By Darryl K. Taft
    05/11/2006 Adobe Releases Spry Framework for AJAX, By AjaxWorld News Desk
    More 
           

          © 2008 ajaximpact.com. All rights reserved.