On May 19, 2011, at 6:31 PM, Juan Ignacio Dopazo wrote:
> On Thu, May 19, 2011 at 9:40 PM, Brendan Eich <[email protected]> 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.
It's common but I see other styles too, including fixed parameter lists. Good
to hear, though -- thanks.
> 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?
I tend not to think so (tertium non datur), but initialiser syntax really blows
for class bodies when you start mixing in declarations. Declarations want to
end with ; or } and never comma after }. So holding to initializer syntax only,
and being disciplined about it, might work.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss