I noted some open issues on "Classes with Trait Composition"

Juan Ignacio Dopazo dopazo.juan at gmail.com
Thu May 19 18:31:24 PDT 2011


On Thu, May 19, 2011 at 9:40 PM, Brendan Eich <brendan at mozilla.com> wrote:
>
> Not taking sides, just asking for you lurkers who use other libraries to do
> similar counting exercises with those libraries, if you all can spare the
> time. Thanks.
>

The reality is that in most cases libraries rarely use the constructor(x) {
this.x = x } pattern because they tend to create an abstraction to define
getters and setters through methods (usually get("prop") and set("prop",
value), but sometimes using getProp() and setProp(value)) and use an object
as a parameter instead of many parameters. Ie:

var widget = new Widget({
  content: 'hello world',
  title: 'example'
});

This is a very common pattern. Personally I always use it because for me
it's always easier to remember parameter names than parameter order. Of
course ES5's getters and setters change the situation a lot.


On a side note, there are a couple of aspects in the "object initializer
extension" proposal that I liked a lot and which value I think is being
underestimated. The class body similar to an object declaration with commas
and colons make it very easy to refactor a class into an object and
viceversa. This is not only useful for writing, but it also helps reading
because it relates complex objects and classes, which is what we're nowadays
doing with the most blogged about pattern in JS, the "module pattern",
(function(){
return {} }()) and new function () {}.

Is a middle ground possible?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110519/11bfc5f8/attachment.html>


More information about the es-discuss mailing list