41 lines
653 B
Plaintext
41 lines
653 B
Plaintext
Assigning ``++this++`` to a local variable is a way to reference parent context inside inner functions. In TypeScript when using arrow functions this happens automatically.
|
|
|
|
This rule raises an issue when ``++this++`` is assigned to a local variable.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
function Foo() {
|
|
let that = this; // Noncompliant
|
|
that.val = 0;
|
|
|
|
setInterval(function() {
|
|
that.val++;
|
|
}, 1000);
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
function Foo() {
|
|
this.val = 0;
|
|
|
|
setInterval(() => {
|
|
this.val++;
|
|
}, 1000);
|
|
}
|
|
----
|
|
|
|
|
|
== Exceptions
|
|
|
|
This rule ignores ``++this++`` used for destructuring.
|
|
|
|
----
|
|
const { foo, bar } = this;
|
|
----
|
|
|