2021-02-02 16:54:43 +01:00

39 lines
610 B
Plaintext

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
----
var obj = {
set foo(value) {
this.fooval = value;
}
};
----
== Compliant Solution
----
var obj = {
set foo(value) {
this.fooval = value;
},
get foo() {
return this.fooval;
}
};
----
or
----
var obj = {
setFoo(value) { // a standard method, not a setter
this.fooval = value;
}
};
----