The reason that your example works is that there are no dependencies between a
, b
, and c
; they are all simple functions. It is not always possible to to just make a reference to a method of an object. In your case, soda
likely calls command
from within the method
reference you create, except that the scope is wrong.
If the function works with either (but not when making a reference to the function), why not just do something like this:
//...
var myFunction = function (err) {
if (err) {
console.log(err);
}
}
if (bool) {
browser.clickAndWait("css=button:first", myFunction);
} else {
browser.click("css=button:first", myFunction);
}
// ...
Or a shorter variation:
// ...
(bool ? browser.clickAndWait : browser.click)("css=button:first", myFunction);
// ...
Alternatively, you may just need to set the scope when you call apply:
// ...
var method = bool ? browser.clickAndWait : browser.click;
method.apply(browser, ["css=button:first", function (err) {
if (err) {
console.log(err);
}
}]);
// ...