Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

87 lines
2.6 KiB
Plaintext

== Why is this an issue?
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.
Specifically, with ES2015, you should simply declare a ``++class++`` and define its methods inside the class declaration.
=== Noncompliant code example
[source,javascript]
----
function MyNonClass(initializerArgs = []) {
this._values = [...initializerArgs];
}
MyNonClass.prototype.doSomething = function () { // Noncompliant
// ...
}
----
=== Compliant solution
[source,javascript]
----
class MyClass {
constructor(initializerArgs = []) {
this._values = [...initializerArgs];
}
doSomething() {
//...
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Declare a "xxx" class and move this declaration of "yyy" into it.
=== Highlighting
xxx.prototype.yyy
'''
== Comments And Links
(visible only on this page)
=== on 4 Feb 2016, 14:22:16 Ann Campbell wrote:
\[~elena.vilchik], why set this to 20min? Since it will be assessed per function, not per class, the shorter time seems more appropriate to me.
=== on 4 Feb 2016, 14:43:09 Elena Vilchik wrote:
\[~ann.campbell.2] Indeed, I've not thought about that
=== on 4 Feb 2016, 18:02:27 Ann Campbell wrote:
BTW [~elena.vilchik], I will understand if you want me to tone down the language of this description.
=== on 5 Feb 2016, 15:54:26 Elena Vilchik wrote:
\[~ann.campbell.2] No, I like it :)
=== on 25 Feb 2016, 13:48:11 Pierre-Yves Nicolas wrote:
On my side, I don't agree with the description. First, JavaScript did not support classes at all before ES2015: prototypes are not classes. Secondly, the biggest argument in favor of applying this rule is that people are much more used to class-based languages rather than prototype-based languages: that does not make prototype-based OOP a nightmare.
Please see \https://en.wikipedia.org/wiki/Prototype-based_programming.
=== on 25 Feb 2016, 14:00:04 Elena Vilchik wrote:
\[~ann.campbell.2], ok, looks like PY is not so happy with this description as I, could you remove couple of "bad"s from it?:)
=== on 25 Feb 2016, 15:36:55 Ann Campbell wrote:
How about now [~pierre-yves.nicolas] and [~elena.vilchik]?
=== on 25 Feb 2016, 15:43:57 Pierre-Yves Nicolas wrote:
It's OK for me, thanks [~ann.campbell.2].
endif::env-github,rspecator-view[]