Skip to content

Instantly share code, notes, and snippets.

@gobwas
Created October 22, 2015 15:28
Show Gist options
  • Save gobwas/d102be7532925cfa5c98 to your computer and use it in GitHub Desktop.
Save gobwas/d102be7532925cfa5c98 to your computer and use it in GitHub Desktop.
Callable object
function Actor(min, max) {
var self = this;
this.id = Math.floor(min + Math.random() * (max - min + 1));
var actor = function() { return self.action.apply(actor, arguments); }
Object.setPrototypeOf(actor, this);
return actor;
}
Actor.prototype.action = function() {
console.log('action', this.id);
}
Object.setPrototypeOf(Actor.prototype, Function.prototype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment