2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2020-06-30 12:48:07 +02:00
|
|
|
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.
|
|
|
|
|
2021-02-02 15:02:10 +01:00
|
|
|
|
2020-06-30 12:48:07 +02:00
|
|
|
This rule also enforces the reverse situation (getter but no setter).
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2020-06-30 12:48:07 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,javascript]
|
2020-06-30 12:48:07 +02:00
|
|
|
----
|
|
|
|
var obj = {
|
|
|
|
set foo(value) {
|
|
|
|
this.fooval = value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2020-06-30 12:48:07 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,javascript]
|
2020-06-30 12:48:07 +02:00
|
|
|
----
|
|
|
|
var obj = {
|
|
|
|
set foo(value) {
|
|
|
|
this.fooval = value;
|
|
|
|
},
|
|
|
|
get foo() {
|
|
|
|
return this.fooval;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
----
|
|
|
|
|
|
|
|
or
|
|
|
|
|
2021-02-02 15:02:10 +01:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,javascript]
|
2020-06-30 12:48:07 +02:00
|
|
|
----
|
|
|
|
var obj = {
|
|
|
|
setFoo(value) { // a standard method, not a setter
|
|
|
|
this.fooval = value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
----
|
2021-09-20 15:38:42 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
Provide a [setter|getter] matching this [getter|setter] or replace this accessor with a simple method.
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|