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
    05/15/2009 A tutorial on Prototype, Google Maps API and the HeatMapAPI
    05/15/2009 The World's Most Popular Programming Language Has Fashion and Luck to Thank
    05/09/2009 Cross-Browser Widgets
    05/08/2009 Monadic parser library for JavaScript
    05/05/2009 They Shoot Browsers, Don’t They?
    05/01/2009 Feature Detection: State of the Art Browser Scripting


    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.