Loading ...
Sorry, an error occurred while loading the content.

get & set

Expand Messages
  • douglascrockford
    I have been asked to have JSLint always warn on use of get and set. How would you feel about that?
    Message 1 of 3 , Mar 27, 2013
    • 0 Attachment
      I have been asked to have JSLint always warn on use of get and set.
      How would you feel about that?
    • Felix E. Klee
      On Wed, Mar 27, 2013 at 11:27 PM, douglascrockford ... The idea is that JSLint would warn when it sees something as the following? o.getX = function () {
      Message 2 of 3 , Mar 27, 2013
      • 0 Attachment
        On Wed, Mar 27, 2013 at 11:27 PM, douglascrockford
        <douglas@...> wrote:
        > I have been asked to have JSLint always warn on use of get and set.
        > How would you feel about that?

        The idea is that JSLint would warn when it sees something as the
        following?

        o.getX = function () { return x; }

        While I much prefer using a getter instead, I don't think the above code
        should trigger a warning. There may be function names that are prefixed
        by `get` and that do not describe what would better be a getter.
      • rodobrist
        ... I use get and set sometimes, I am aware that they are: 1. Not overly performant (js perf type diagnostics). 2. Not compatible in IE
        Message 3 of 3 , Mar 27, 2013
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "douglascrockford" <douglas@...> wrote:
          >
          > I have been asked to have JSLint always warn on use of get and set.
          > How would you feel about that?
          >

          I use get and set sometimes, I am aware that they are:

          1. Not overly performant (js perf type diagnostics).
          2. Not compatible in IE < 9 browsers.

          But in some circumstances they seem more suitable then the alternative of calling getProperty() and setProperty() (es3 attempt of getter/setter).

          These circumstances are:
          1. Chrome extension development
          2. Node js
          3. Working for lovely bosses who tell you they don't care about IE8

          I think es5 getter/setter are cleaner when used correctly.

          Property access was built into the syntax of javascript, I prefer to keep it that way:

          object.property
          vs
          object.callFuncToGetProperty()


          Are there any other reasons not to use them besides what I mentioned?
        Your message has been successfully submitted and would be delivered to recipients shortly.