|
Helping ordinary people create extraordinary websites! |
Event Handlers and Callback Functions in JavaScriptBy Sjoerd Visscher2006-08-19
Higher Order Programming again
var sayHi=new Alerter('Hello, world!');
A nice feature of Microsoft's delegates is that you can create a single composite deligate from several delegates. It looks less messy than inserting an anonymous function. Let's do that in Javascript too, by extending the function prototype. Function.prototype.andThen=function(g) {
Now we can write: setTimeout((sayHi.invoke).andThen(sayBye.invoke),2000); Several callbacksWith the function Manager() {
Tutorial Pages: » Introduction » The Trick » Higher Order Programming again » Conclusion This article is licensed under the Creative Commons |
|