On 31 May 2012 11:33, T.J. Crowder <[email protected]> wrote:
> All,
>
> I was going to lurk longer before raising this, and apologies if it's been
> raised before, but the discussion of object extension literals sort of
> brought it up.
>
> TL;DR: I wonder if the object extension literal might reasonably become a
> fit-for-purpose `with`. For years I've thought the `with` problem could
> be solved relatively easily by using a leading dot (not an original
> thought, but I hesitate to even mention where I've seen it before -- VB)
> and presumably a different keyword. Now I wonder if we don't even need a
> keyword.
>
> The detail:
>
> The current strawman supports
>
> o.{
> a: "foo",
> b = "bar"
> };
>
> ...where the first is [[DefineOwnProperty]] and the second is [[Put]]. The
> discussion has moved on a bit with people suggesting using semicolons and
> allowing calls as well:
>
> o.{
> a: "foo";
> b = "bar";
> c.f(); // e.g., o.c.f()
> };
>
> or with parens:
>
> o.(
> a: "foo";
> b = "bar";
> c.f(); // e.g., o.c.f()
> );
>
> To me, that starts looking a lot like a series of statements rather than
> definitions/assignments -- and specifically, a lot like `with`.
>
> So that leads me to wonder about something along these lines:
>
> o.{
> .a: "foo"; // [[DefineOwnProperty]]
> .b = "bar"; // [[Put]]
> .c.f(); // E.g., o.c.f();
> .d = .a; // E.g., o.d = o.a;
> .x.{
> .y = 2; // E.g., o.x.y = 2;
> };
> };
>
> E.g., a combination of object extension literal and an improved `with`.
>
> -- T.J.
>
Sorry, a couple of points I should have made about the above:
1. I used {} rather than () because this is a block (thus `let` works
within it).
2. I originally envisioned this as a statement (of course, I was originally
thinking we'd have a new keyword, until the object extension literal
discussion), but it could be an expression; if so, presumably the result of
the expression would be the object.
3. The leading dot makes tools support a bit simpler.
4. The leading dot seems, to me, to be more explicit than just having the
first symbol on the left being implicitly a property the object. EIBTI
5. There would be a temptation to try to backfit this on object
initializers as well, but I'd be worried about the confusion it creates
(not least for parsers) supporting _both_ syntaxes within an object
initializer. If this new thing is an expression (see #2), there's no
need, because o = {}.{ .a = 5; .b = .a; }; works just fine.
-- T.J.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss