-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Comments
Not really. You can find several instances of @jashkenas and @michaelficarra saying they're explicitly avoided in CoffeeScript. |
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. |
@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). |
@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 |
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.
The text was updated successfully, but these errors were encountered: