Missing ‘this’ qualifier¶
ID: js/missing-this-qualifierKind: problemSecurity severity: Severity: errorPrecision: highTags: - quality - reliability - correctness - methodsQuery suites: - javascript-security-and-quality.qls
Click to see the query in the CodeQL repository
JavaScript methods can call other methods of the same class instance through the use of thethis keyword. In other object-oriented languages such as Java, the use of thethis keyword for such method calls is optional. It is howevernot optional in JavaScript. If thethis keyword is left out, the call is a regular function call.
Recommendation¶
Add thethis keyword as the receiver of the call.
Example¶
In the following example, the call tosetAudioProperties will call an undeclared global function, andnot the method defined later in the class.
classAudio3D{setAudioStream(){// ...setAudioProperties();// ...}setAudioProperties(){// ...}}
The problem can be fixed by adding thethis keyword to the call:this.setAudioProperties().
References¶
MDN:Classes