Automate auto-binding of prototype methods

This commit is contained in:
Andrew Stewart 2015-06-25 12:33:13 -07:00
parent fd564f61f8
commit 8fbe9b9c4d
1 changed files with 6 additions and 15 deletions

View File

@ -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);