How do I make this work:
class TestClass { doMethod1 (arg1, arg2, cb) { this.doMethod2(arg1, arg2, function (result){cb (result)}); } doMethod2 (arg1, arg2, cb) { this.doMethod3(arg1, arg2, function(result){cb (result)}); } doMethod3 (arg1, arg2, cb) { var result = arg1 + arg2; cb(result); } }
test = new TestClass;
test.doMethod3 (1,1, cb); test.doMethod2 (1,1, CB);
Both work.
test.doMethod1 (1,1, CB);
EDIT: It actually works.
I circumvented related lexical issues using the bold arrow syntax:
doMethod1 (arg1, arg2, cb) { this.doMethod2(arg1, arg2, (result) => {cb (result)}); }
Ensures that "this" in doMethod1 matches the "this" in the anonymous callback function.
source share