Composing DSLs in JavaScript
Date : 2008 03 28 Category : Tech & Development
PLAIN TEXT
JAVASCRIPT:
TheRulesAre(function() { with(this) { a(Player).mayNot('buyProperty').unless(function(player, property) { return property.owner === null && player.funds>= property.price; }); a(Property).mayNot('addHouse').when(it().isMortgaged()); }});
TheRulesAre(function() { with(this) { a(Player).mayNot('buyProperty').unless(function(player, property) { return property.owner === null && player.funds>= property.price; }); a(Property).mayNot('addHouse').when(it().isMortgaged()); }});
Composing DSLs in JavaScript is James Coglan's latest perusal into fun with JavaScript and DSLs.
He walks through the building of this DSL in a step by step manner. He uses his JS.Class library, but you could of course substitute your favourite JavaScript library.