In case we need to call function of our own class we always have to use this
class ExamPage {
tabClear() {
page.clear(this.examName);
page.clear(this.examVersionId);
}
createNew() {
describe('Create new' , function() {
it('Clear input boxes', function() {
this.tabClear(); // HERE the this.tabClear() is the answer
});
});
}
}
But in fact, we also should use arrow function notation, which will keep the correct scope of the this:
createNew() {
// the function () is replaced with arrow function
describe('Create new' , () => {
it('Clear input boxes', () => {
this.tabClear(); // HERE the this.tabClear() is the answer
});
});
}
see more details about arrow functions here:
small cite:
“Arrow function expressions are a compact form of function expressions that omit the function keyword and have lexical scoping of this.” Basically the Arrow Function helps you retain a certain scope automatically. If you look at the outputted code from the compiler, it just creates a var _this = this; and it is used inside the function.