GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Missing ‘this’ qualifier — CodeQL query help documentation

Missing ‘this’ qualifier¶

ID: js/missing-this-qualifier
Kind: problem
Security severity: 
Severity: error
Precision: high
Tags:
   - quality
   - reliability
   - correctness
   - methods
Query suites:
   - javascript-code-quality.qls
   - 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 the this keyword. In other object-oriented languages such as Java, the use of the this keyword for such method calls is optional. It is however not optional in JavaScript. If the this keyword is left out, the call is a regular function call.

Recommendation¶

Add the this keyword as the receiver of the call.

Example¶

In the following example, the call to setAudioProperties will call an undeclared global function, and not the method defined later in the class.

class Audio3D {
  setAudioStream(){
    // ...
    setAudioProperties();
    // ...
  }

  setAudioProperties(){
    // ...  
  }
}

The problem can be fixed by adding the this keyword to the call: this.setAudioProperties().

References¶

  • MDN: Classes

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.