On Wed, Jan 25, 2012 at 10:28 PM, Brendan Eich <bren...@mozilla.org> wrote:

> The form you showed was every bit as imperative. I don't like punning 'if'
> statements into object literals as a special form.Why not switch statements?
> Why not loops with computed property names?

Switch statements could work, loop probably not.
You can, usually meaningfully, make a syntactic category conditionally
processed.
For statements there is "if", for expressions "?:". This suggestion is
about conditionally processed declarations.
ECMAScript don't usually make a big deal about declarations as being
different from statements (which is probably why people started doing
function statements). An object literal is the only scope where only
declarations are valid, so it makes sense that that is where a wish
for conditional declarations appear.

> Restricting the consequent or loop body to be more declarative does not
> remove the ability to do a great many imperative things in the initial value
> expressions.
>
> We have imperative forms (statements). We have object literals. Keeping them
> from blurring together is better for readability in my opinion.

ACK. readability would suffer with the suggested syntax.

> Add to this the relative rarity of needing such an if. Then add the ability 
> to use .{ or
> whatever it'll be called.

The .{ and <| operators are trying to make complex imperative
initialization sequences into (shorter) expressions. We are doing the
computation in order to create a single value, and we don't really
care about the way it's done, so it seems like a prime target for
becoming an expression, taking the imperatives out of what is really a
value operation. If you repeat a sequence of statements often enough,
it'll be abstracted into either a function or, in this case, an
operator.
The argument here seems to be that the need for conditionally
declaring properties of an object literal isn't happening often enough
that it warrants an abstraction. (And that seems reasonable from what
I've seen too).

/L
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to