The requested page is not available for the requested platform. You are viewing the content for Default platform.

Suspicious use of this qualifier

Note

The Suspicious use of this qualifier code issue is JavaScript specific.

CodeRush Classic shows the Suspicious use of this qualifier code issue if "this" qualifier is used inside an inner function.

Fix

Replace the initial variable with a new local variable, declared outside of the inner function.

Purpose

Highlights the suspicious use of the "this" qualifier inside an inner function, since it may yield unexpected results.

Example

var Sum = new function () {
    var element1 = document.getElementById("sumElement1");
    var element2 = document.getElementById("sumElement2");
    this.val1 = parseInt(element1.nodeValue);
    this.val2 = parseInt(element2.nodeValue);
    Proc = function () {
        return this.val1 + this.val2;
    }
    var resElement = document.getElementById("result");
    resElement.nodeValue = this.Proc();
};

Fix:

var Sum = new function () {
    var element1 = document.getElementById("sumElement1");
    var element2 = document.getElementById("sumElement2");
    ProcessClick();
    this.val1 = parseInt(element1.nodeValue);
    this.val2 = parseInt(element2.nodeValue);
    var val1 = this.val1;
    var val2 = this.val2;
    Proc = function () {
        return val1 + val2;
    }
    var resElement = document.getElementById("result");
    resElement.nodeValue = this.Proc();
};