rspec/rules/S3525/rule.adoc

34 lines
900 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
Originally JavaScript didn't support ``++class++``es, 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 ``++class++``es. The new syntax is more expressive and clearer, especially to those with experience in other languages.
2020-06-30 12:48:39 +02:00
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
Specifically, with ES2015, you should simply declare a ``++class++`` and define its methods inside the class declaration.
2020-06-30 12:48:39 +02:00
== Noncompliant Code Example
----
function MyNonClass(initializerArgs = []) {
this._values = [...initializerArgs];
}
MyNonClass.prototype.doSomething = function () { // Noncompliant
// ...
}
----
== Compliant Solution
----
class MyClass {
constructor(initializerArgs = []) {
this._values = [...initializerArgs];
}
doSomething() {
//...
}
}
----