Automate auto-binding of prototype methods
This commit is contained in:
parent
fd564f61f8
commit
8fbe9b9c4d
21
lib/robot.js
21
lib/robot.js
|
@ -31,21 +31,12 @@ var Robot = module.exports = function Robot(opts) {
|
||||||
|
|
||||||
validator.validate(opts);
|
validator.validate(opts);
|
||||||
|
|
||||||
var methods = [
|
// auto-bind prototype methods
|
||||||
"toString",
|
for (var prop in Object.getPrototypeOf(this)) {
|
||||||
"halt",
|
if (this[prop] && prop !== "constructor") {
|
||||||
"startDevices",
|
this[prop] = this[prop].bind(this);
|
||||||
"startConnections",
|
}
|
||||||
"start",
|
}
|
||||||
"initRobot",
|
|
||||||
"initDevices",
|
|
||||||
"initConnections",
|
|
||||||
"log"
|
|
||||||
];
|
|
||||||
|
|
||||||
methods.forEach(function(method) {
|
|
||||||
this[method] = this[method].bind(this);
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this.initRobot(opts);
|
this.initRobot(opts);
|
||||||
this.initConnections(opts);
|
this.initConnections(opts);
|
||||||
|
|
Loading…
Reference in New Issue