Bind passed function to Robot by default

This commit is contained in:
Andrew Stewart 2015-03-17 14:22:14 -07:00
parent 28415f0b74
commit a17c70a18b
2 changed files with 9 additions and 5 deletions

View File

@ -54,10 +54,14 @@ var Robot = module.exports = function Robot(opts) {
return;
}
this[name] = opt;
if (_.isFunction(opt)) {
this[name] = opt.bind(this);
if (opts.commands == null && _.isFunction(opt)) {
this.commands[name] = opt;
if (opts.commands == null) {
this.commands[name] = opt.bind(this);
}
} else {
this[name] = opt;
}
}, this);

View File

@ -65,7 +65,7 @@ describe("Robot", function() {
});
it("sets other obj params as values on the robot", function() {
expect(robot.extraFunction).to.be.eql(extraFunction);
expect(robot.extraFunction).to.be.a("function");
expect(robot.extraValue).to.be.eql("Hello World");
});
@ -96,7 +96,7 @@ describe("Robot", function() {
});
it("sets #commands to the additionally provided functions", function() {
expect(robot.commands).to.be.eql({ sayHello: robot.sayHello });
expect(robot.commands.sayHello).to.be.a("function");
});
});