This post is extremely nerdy, so for those of you who don't care about Javascript's object model, have a good weekend, you may skip the rest of the post.
OK, so now that I'm talking to the nerds, here's some neat Javascript voodoo. I really like monkeying around with runtimes, and one reason that I like Python

so much is that it lets you do all kinds of perverse things to the runtime with some very elegant effects. One thing it lets you do is define "callable" objects - objects that you can call like any plain old function. Classes, eg, are callable; this invokes the constructor and returns a new instance of the class. This maintains a similar syntax to other languages, except it's cleaner:
myInstance = MyClass() # python
var myInstance = new MyClass(); // Javascript
MyClass* myInstance = new MyClass(); // C++
MyClass* myInstance = [[[MyClass alloc] init] autorelease]; // Objective-C
This also makes for very elegant RPC calls. You can, eg, create a callable instance that you can use like a regular function, but takes care of all the grotty marshalling and connection management behind the scenes. Once you set it up, you can use the instance like any other function:
import xmlrpclib
server = xmlrpclib.ServerProxy('http://time.xmlrpc.com/RPC2')
print server.currentTime.getCurrentTime()
I'm writing a Javascript XML-RPC client library for work and I really wanted to be able to do something that elegant, like:
getCurrentTime = XMLRPCMethod('http://time.xmlrpc.com/RPC2', 'currentTime.getCurrentTime');
alert(getCurrentTime());
But in Javascript, you can only call things that are actual functions.
However, since functions are first-class objects, you can bind your own attributes to them like any other object. You can access them from inside the body of the function by using the special variable arguments.callee:
function Greeter(yourName) {
var result = function(timeOfDay) {
alert('Good ' + timeOfDay + ', ' + arguments.callee.yourName);
};
result.yourName = yourName;
return result;
}
greetZ = Greeter('Zobar');
greetP = Greeter('Paul');
greetZ('afternoon'); // 'Good afternoon, Zobar'
greetZ('evening'); // 'Good evening, Zobar'
greetP('evening'); // 'Good evening, Paul'
When I figured this out it
blew my mind, and while I doubt its day-to-day practicality, I thought it's a handy tool for Javascripters to have. I also plan to make the XML-RPC library public, once I clean it up a bit, test it in MSIE, and finish the documentation.
- Z
That's certainly possible. Much has been made of the rivalry between us [at least by the Beast], and I don't think a single issue goes by without them mentioning how awful they think we are. For our part, we believe our readership [270,000] speaks for itself.
On the other hand, calling people up and leaving crabby messages isn't really their MO. They would much prefer to pull an elaborate prank. Then they'd have something to write about, and they wouldn't have to [God forbid] leave the office.
- Z
I wonder if any of those letters you are receiving are from the Beast?