All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S3525.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

Originally JavaScript didn’t support classes, and class-like behavior had to be kludged using things like prototype assignments for "class" functions. Fortunately, ECMAScript 2015 added classes, so any lingering prototype uses should be converted to true classes. The new syntax is more expressive and clearer, especially to those with experience in other languages.

Specifically, with ES2015, you should simply declare a class and define its methods inside the class declaration.

Noncompliant code example

function MyNonClass(initializerArgs = []) {
  this._values = [...initializerArgs];
}

MyNonClass.prototype.doSomething = function () {  // Noncompliant
  // ...
}

Compliant solution

class MyClass {
  constructor(initializerArgs = []) {
    this._values = [...initializerArgs];
  }

  doSomething() {
    //...
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy