diff --git a/lib/robot.js b/lib/robot.js index aabda22..326a137 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -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); diff --git a/spec/lib/robot.spec.js b/spec/lib/robot.spec.js index 4c1c347..d93849b 100644 --- a/spec/lib/robot.spec.js +++ b/spec/lib/robot.spec.js @@ -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"); }); });