Replicate Python __call__ in JS
http://stackoverflow.com/questions/17866654/replicating-pythons-call-in-javascript
JavaScript
// based on this SO post: http://stackoverflow.com/questions/17866654/replicating-pythons-call-in-javascript
var ObjectCallable = function(cls) {
var f = function() { return f.__call__.apply(f, arguments); }
var k;
for (k in cls) {
console.log('k', k)
f[k] = cls[k];
}
return f;
}
var Foo = {
getMessage: function() {
return "hello world";
},
__call__: function() {
console.log(this.getMessage());
}
}
Foo = ObjectCallable(Foo);
Foo();