First, event programming or inheritance is orthogonal to DCI. You can do DCI without inheritance and with event programming (or without).
JavaScript is, to some extent, one of the best languages ββfor DCI. Most languages ββhave some problems with the following DCI. In JavaScript, problems can be solved if there is a finalizer, but the lack of a finalizer means that you have to "manage" your value, meaning some kind of noilerplate code.
I wrote an example in JavaScript, which I will post on the Internet at http://fullOO.info , where you will find examples of Trygve, Jim, and I created with some other people also created.
fullOO.info is also the answer to where you could go to learn more about DCI, or you can join the google group to discuss DCI.
An example that I wrote in JS is a canonical money transfer using the DCI example, and the interesting part (that is, everything except the template / library code) can be seen below:
var moneyTransferContext = function(sourcePlayer, destinationPlayer, amount) { var source = { withdraw: function() { var text = "Withdraw: " + amount; this.log.push(text); this.balance -= amount; console.log("Balance: " + this.balance); } }, destination = { deposit: function() { var text = "Deposit: " + amount; this.log.push(text); this.balance += amount; console.log("Balance: " + this.balance); } }; source = assign(source).to(sourcePlayer); destination = assign(destination).to(destinationPlayer); return { transfer: function() { source.withdraw(); destination.deposit(); return this; } }; }, sourceAccount = { log: [], balance: 100 }, destinationAccount = { log: [], balance: 0 }; moneyTransfer(sourceAccount, destinationAccount, 25).transfer().unbind();
The rest can be seen at http://jsfiddle.net/K543c/17/
source share