From 8fbe9b9c4dff29fa595303618aaa051fec89822e Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Thu, 25 Jun 2015 12:33:13 -0700 Subject: [PATCH] Automate auto-binding of prototype methods --- lib/robot.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/robot.js b/lib/robot.js index 922233d..4fffbc1 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -31,21 +31,12 @@ var Robot = module.exports = function Robot(opts) { validator.validate(opts); - var methods = [ - "toString", - "halt", - "startDevices", - "startConnections", - "start", - "initRobot", - "initDevices", - "initConnections", - "log" - ]; - - methods.forEach(function(method) { - this[method] = this[method].bind(this); - }, this); + // auto-bind prototype methods + for (var prop in Object.getPrototypeOf(this)) { + if (this[prop] && prop !== "constructor") { + this[prop] = this[prop].bind(this); + } + } this.initRobot(opts); this.initConnections(opts);