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:
-
-
with(JavaScript) {
-
metaprogramming.is(”possible”);
-
}
-
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:
-
-
create_dynamic_field(”show”, “us-state-field”, “country”, “United States”);
-
create_dynamic_field(”show”, “province-field”, “country”, “Canada”);
-
create_dynamic_field(”show”, “brutus”, “state”, [”Ohio”, “Michigan”]);
-
morphs into the following DSL:
-
-
show(”us-state-field”).when(”country”).is(”United States”);
-
show(”province-field”).when(”country”).is(”Canada”);
-
show(”brutus”).when(”us-state”).is(”Ohio, Michigan”);
-
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