Metaprogramming / DSL JavaScript Presentation

Written by on March 28th, 2007 in Ajax News.

I wish I could have seen Adam McCrea give a presentation on JavaScript Metaprogramming and how:

JAVASCRIPT:

  1.  
  2. with(JavaScript) {
  3.   metaprogramming.is(”possible”);
  4. }
  5.  

His slides do a good job at explaining the talk (which is tough to do).

The presentation quickly delves into an example where he evolves the solution to the spec:

show us-state field when country select box is “United States”
show province field when country select box is “Canada”
show brutus when us-state select box is “Ohio” or “Michigan”

A typical solution in JavaScript:

JAVASCRIPT:

  1.  
  2. create_dynamic_field(”show”, “us-state-field”, “country”, “United States”);
  3. create_dynamic_field(”show”, “province-field”, “country”, “Canada”);
  4. create_dynamic_field(”show”, “brutus”, “state”, [”Ohio”, “Michigan”]);
  5.  

morphs into the following DSL:

JAVASCRIPT:

  1.  
  2. show(”us-state-field”).when(”country”).is(”United States”);
  3. show(”province-field”).when(”country”).is(”Canada”);
  4. show(”brutus”).when(”us-state”).is(”Ohio, Michigan”);
  5.  

and it goes on from here to delve deep into the world of dependencies and metaprogramming with JavaScript.

Source: Ajaxian
Original Article: http://ajaxian.com/archives/metaprogramming-dsl-javascript-presentation

Leave a Reply

You must be logged in to post a comment.



Site Navigation