Event.Behavior: DSL for JavaScript
Written by on April 5th, 2007 in Ajax News.
Ryan Johnson is quite prolific these days. His newest creation is Event.Behavior, a domain specific language for describing and defining events in your JavaScript applications. It attempts to approximate how one would describe an event in the english language and allows you to extend it with your own verbs.
The library was inspired by Adam McCrea’s presentation on Meta programming with JavaScript, and is built on top of Prototype 1.5.
Here are some examples:
JAVASCRIPT:
-
-
with (Event.Behavior) {
-
show(’postal_code_field’).when(’country_select’).is(’United States’).or(’Canada’);
-
-
set_style(styles).on(paragraphs).when(selects).change();
-
-
add_class_name(’black’).to(’paragraph’).when(’color_select’).is(’black’);
-
}
-
Source: Ajaxian
Original Article: http://ajaxian.com/archives/eventbehavior-dsl-for-javascript