
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.
56 lines
952 B
Plaintext
56 lines
952 B
Plaintext
== Why is this an issue?
|
|
|
|
When an object is created with a setter for a property but without a getter for that property, the property is inaccessible and is thus useless.
|
|
|
|
|
|
This rule also enforces the reverse situation (getter but no setter).
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
var obj = {
|
|
set foo(value) {
|
|
this.fooval = value;
|
|
}
|
|
};
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
var obj = {
|
|
set foo(value) {
|
|
this.fooval = value;
|
|
},
|
|
get foo() {
|
|
return this.fooval;
|
|
}
|
|
};
|
|
----
|
|
|
|
or
|
|
|
|
|
|
[source,javascript]
|
|
----
|
|
var obj = {
|
|
setFoo(value) { // a standard method, not a setter
|
|
this.fooval = value;
|
|
}
|
|
};
|
|
----
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Provide a [setter|getter] matching this [getter|setter] or replace this accessor with a simple method.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|