Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "setter is defined without getter" a JSHint error?

Reference jsfiddle

var obj = {
  set bla(k) {
    console.log(k);
  }
};

JSHint flags this as "setter is defined without getter". I am sure there is a way to turn this off, but why is this an error at all? Everything I have seen JSHint flag has had a reasonable explanation. I can't come up with a reason for why this is a bad thing.

like image 730
Azeem Bande-Ali Avatar asked Apr 30 '14 23:04

Azeem Bande-Ali


1 Answers

I don't think JSHint has a good reason to warn about this situation. I don't see anything in the specification (http://www.ecma-international.org/publications/standards/Ecma-262.htm, pages 30-31) that requires there to be a getter if there is a setter or vice versa, and it is easy to imagine a setter that doesn't imply a getter. For example, you might want to set a dirty flag in a setter. There would be no reason to define a getter.

I did not see a justification in the JSHint source, or its history.

like image 51
Dave Schweisguth Avatar answered Sep 19 '22 03:09

Dave Schweisguth