75 lines
1.1 KiB
Plaintext
75 lines
1.1 KiB
Plaintext
![]() |
include::../description.adoc[]
|
||
|
|
||
|
Additionally, one shouldn't use a class to define exclusively static methods. Instead one can use a module, or better, export each function separately.
|
||
|
|
||
|
== Why is this an issue?
|
||
|
|
||
|
Using an empty class serves no purpose and can hinder the readability of the code.
|
||
|
|
||
|
[source,javascript]
|
||
|
----
|
||
|
class Foo {
|
||
|
static bar() {
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
|
||
|
//=== What is the potential impact?
|
||
|
|
||
|
== How to fix it
|
||
|
|
||
|
You can export the functions that you wish to make available.
|
||
|
|
||
|
[source,javascript]
|
||
|
----
|
||
|
export function bar() {
|
||
|
// ...
|
||
|
}
|
||
|
----
|
||
|
|
||
|
=== Code examples
|
||
|
|
||
|
==== Noncompliant code example
|
||
|
|
||
|
[source,javascript,diff-id=1,diff-type=noncompliant]
|
||
|
----
|
||
|
class Foo {
|
||
|
static bar() {
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class DoAndLog {
|
||
|
constructor () {
|
||
|
console.log('I\'m done!');
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
|
||
|
==== Compliant solution
|
||
|
|
||
|
[source,javascript,diff-id=1,diff-type=compliant]
|
||
|
----
|
||
|
export function bar() {
|
||
|
// ...
|
||
|
}
|
||
|
|
||
|
function doAndLog() {
|
||
|
console.log('I\'m done!');
|
||
|
}
|
||
|
----
|
||
|
|
||
|
//=== How does this work?
|
||
|
|
||
|
//=== Pitfalls
|
||
|
|
||
|
//=== Going the extra mile
|
||
|
|
||
|
//== Resources
|
||
|
|
||
|
//=== Documentation
|
||
|
//=== Articles & blog posts
|
||
|
//=== Conference presentations
|
||
|
//=== Standards
|