JavaScript DSL

JavaScript is such a great little language. It allows you to easily create a DSL. Let's setup a small DSL to do some math:

Number.prototype.plus = function(i) {
    return Number(this.valueOf()+i);
};

Number.prototype.minus = function(i) {
    return Number(this.valueOf()-i);
};

In the above code we change the prototype of the Number object to include two new methods (plus and minus). They return a new Number object, whilst doing the calculation.

So with this little effort you can already do:

(5).plus(4).minus(1); // 8

The above example isn't really practical of course, just using 5+4-1 is a lot easier, but you get the point.