# no-this-outside-of-class

Rule `unicorn/no-this-outside-of-class`. Disallow `this` outside of classes.

- Source: unicorn
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 9.5M weekly downloads of presets that enable it
- Trend: +30.3% last quarter
- Rank: #1121 by reach, #1140 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-this-outside-of-class` | no | no | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-this-outside-of-class.md) |
| Biome | `nursery/noThisOutsideOfClass` | no | no | group nursery, since 2.5.12 | [docs](https://biomejs.dev/linter/rules/no-this-outside-of-class/) |

## Code examples

### Incorrect: the rule reports this

```js
function Foo(value) {
  this.value = value;
}
```

```js
const foo = {
  method() {
    return this.value;
  }
};
```

```js
Foo.prototype.method = function () {
  this.value();
};
```

### Correct: the rule accepts this

```js
class Foo {
  constructor(value) {
    this.value = value;
  }

  method() {
    return this.value;
  }
}
```

```js
class Foo {
  method() {
    const getValue = () => this.value;
    return getValue();
  }
}
```

```ts
const foo = {
  method(this: Foo) {
    return this.value;
  }
};
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-this-outside-of-class": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noThisOutsideOfClass": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |

## Related rules

- [unicorn/require-array-sort-compare](https://lintradar.dev/rules/unicorn/require-array-sort-compare.md): Require a compare function when calling `Array#sort()` or `Array#toSorted()`.
- [unicorn/no-unreadable-for-of-expression](https://lintradar.dev/rules/unicorn/no-unreadable-for-of-expression.md): Disallow unreadable iterable expressions in `for…of` and `for await…of` loop headers.
- [unicorn/no-useless-template-literals](https://lintradar.dev/rules/unicorn/no-useless-template-literals.md): Disallow useless template literal expressions.
- [unicorn/no-top-level-assignment-in-function](https://lintradar.dev/rules/unicorn/no-top-level-assignment-in-function.md): Disallow assigning to top-level variables from inside functions.
- [unicorn/no-invalid-argument-count](https://lintradar.dev/rules/unicorn/no-invalid-argument-count.md): Disallow calling functions and constructors with an invalid number of arguments.
- [unicorn/no-unsafe-string-replacement](https://lintradar.dev/rules/unicorn/no-unsafe-string-replacement.md): Disallow non-literal replacement values in `String#replace()` and `String#replaceAll()`.

---

Web page: https://lintradar.dev/rules/unicorn/no-this-outside-of-class. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
