Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getter/setter syntax after IE8 #4156

Closed
woubuc opened this issue Dec 2, 2015 · 4 comments
Closed

Getter/setter syntax after IE8 #4156

woubuc opened this issue Dec 2, 2015 · 4 comments

Comments

@woubuc
Copy link

woubuc commented Dec 2, 2015

I think everyone here knows how @jashkenas feels about getters and setters (for those who don't: he hates them). The official reason for their absence in Cofeescript has always been to maintain browser support, as per #3698 and a bunch of others, but that is obviously nothing more than an excuse.

But here's the thing: whether or not it is an excuse or an actual compatibility consideration, on january 12th 2016 the support for IE8 will officially end, meaning the only remaining browser to not support getters and setters will be officially dead. After that, all browsers and Javascript platforms will support it.

So what I want to know is: now that there is literally no more reason not to support this feature (other than an apparent personal grudge of some kind that you hold against the words get and set), will a proper getter/setter syntax finally be implemented? If not for you, then for all those devs who have been asking for this for a long time.

@vendethiel
Copy link
Collaborator

The official reason for their absence in Cofeescript has always been to maintain browser support, as per #3698 and a bunch of others, but that is obviously nothing more than an excuse.

Not really. You can find several instances of @jashkenas and @michaelficarra saying they're explicitly avoided in CoffeeScript.

here in #3698, here in #2902, #64, #322, #451, #949

@michaelficarra
Copy link
Collaborator

To summarise the sentiment, we don't think it's a good thing that getters/setters enable you to add effects to an expression that does not look like it should have effects. If you want an expression to have some effect, use a function to make it obvious to consumers.

@woubuc
Copy link
Author

woubuc commented Dec 2, 2015

@michaelficarra For an existing in-house application I'm currently working on, there is a property in an object that we need to adjust the value of slightly, to be compatible with a new add-on we're implementing. It is already used extensively throughout the code so implementing a getter and setter here in the Coffeescript code instead of having to implement a set of hacks to achieve the same result would be the best and easiest option.

For 95% of the cases, I agree that get/set shouldn't be used, but it would just be very useful to have them available in edge cases like this.

Edit: Also @vendethiel saying I think that working in a JS without them is far more pleasant than working in a JS with them as in #3698 to me does not mean the same as saying you're explicitly avoiding them in Coffeescript, but is rather a general opinion on the use of them. The older references you linked to state that getters and setters are non-standard and unsupported in most browsers (which at the time was indeed true).

@lydell
Copy link
Collaborator

lydell commented Dec 2, 2015

@woubuc Considering what you said in the above comment, I’d say use something like the following:

Object.defineProperty(obj, 'key', {
  get: -> ...
  enumerable: true
})

That is not a hack. I don’t see why you’d want syntax for getters and setters if you think that they should be avoided in 95% of the cases, and you only plan to use it in a few edge cases.

I use the above technique myself in a project (even though I dislike getters and setters):

class Foo
  constructor: (arg, @_parent) ->
    ...
    Object.defineProperty(this, 'options', {
      get: => @_parent.options
      enumerable: true
    })

The reason I use a getter here is to assure that the options property always is up-to-date with @_parent.options (@_parent might have its options property reassigned). And I’m perfectly fine with that (even though the environments I use the above code in do support getter and setter JS syntax).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants