This is a bit of a hack to provide support for call like in python to objects.
function Object() {
var self = this;
var o = function ( ) {
if (‘__call__’ in o) {
o.__call__.apply(this, arguments);
}
else {
throw “Object not callable”;
}
}
for (var k in self) if (self.hasOwnProperty(k)) {
o[k] = self[k];
}
return o;
};
var myObj = {
__call__: function(){ alert(‘hello, world ‘+this.foo) },
};
myObj();
var o2 = {
test: myObj,
foo: 23
}
o2.test();
Clearly a hack, and has a number of problems. only works for literals and plain old Objects, not objects created with constructor functions. also messes up the typeof and instanceof stuff (says function and Function rather than object and Object)
