why are setter/getter parameter lists restricted?

Allen Wirfs-Brock allen at wirfs-brock.com
Mon May 11 23:31:56 UTC 2015

On May 11, 2015, at 10:38 AM, Michael Ficarra wrote:

> We all know getters must have no parameters and setters must have exactly one parameter. But I recently encountered a bug in one of my projects where default values were not being properly handled for setter parameters. The only reason it would make sense to allow default values on a setter parameter is if the use case of pulling the setter off the property descriptor was considered. But if that use case was considered, wouldn't the use case of setting an arbitrary function to the get/set fields of the property descriptor be just as valid?
> For consistency, either FormalParameters should be used in the getter/setter parameter list positions or only BindingIdentifier and BindingPattern should be allowed for the setter parameter.

The single formal design decision was made when ES5 was being developed.  It practice, it some seem to have been accepted just fine.

Replacing the current single FormalParameter  (which allows for the possibility of a default value initializer) with an alternative production that didn't allow a default value would just be creating a different inconsistency as it would be the only place a formal parameter could have have a default value initializer. 

Regardless, ES6 and the syntax is set.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150511/3bcf01e6/attachment.html>

More information about the es-discuss mailing list