with

Dmitry Soshnikov dmitry.soshnikov at gmail.com
Thu Nov 17 03:53:59 PST 2011


On 17.11.2011 11:41, David Herman wrote:
> On Nov 16, 2011, at 11:27 PM, Mark S. Miller wrote:
>
>> On Wed, Nov 16, 2011 at 11:24 PM, David Herman <dherman at mozilla.com 
>> <mailto:dherman at mozilla.com>> wrote:
>>
>>        obj with { foo: 12 } with { bar: 13 } with { baz: 17 }
>>
>>
>> I don't get it yet. What do you mean by "dynamically extending 
>> prototype chains"? What does the above expression do and evaluate to?
>
> My first answer was glib, sorry. I'm proposing `with' as a replacement 
> syntax for <|. So the above expression evaluates to the same as
>
>     obj <| { foo: 12 } <| { bar: 13 } <| { baz: 17 }
>
> which in turn, if I've got this right, would be equivalent to
>
>     Object.create(Object.create(Object.create(obj, { foo: { value: 12,
>                                                             
> enumerable: true,
>                                                             
> configurable: true,
>                                                             writable: 
> true } }),
>                                 { bar: { value: 13,
>                                          enumerable: true,
>                                          configurable: true,
>                                          writable: true } }),
>                   { baz: { value: 17,
>                            enumerable: true,
>                            configurable: true,
>                            writable: true } })
>
> since in this example I only used the object literal variant. (The 
> function, array, etc variants do things that Object.create can't do.)
>

Once again, it's absolutely the same approach which I showed yesterday 
with using `extends' 
(https://mail.mozilla.org/pipermail/es-discuss/2011-November/018478.html).

In order to avoid confusion with `with', which had old and used for 
years semantics, I still propose to use `extends' instead.

Is it just great that we have the _same inheritance model_ as for simple 
objects as well as for classes?

// object inherits
var foo extends bar {
   x: 100
}

// class inherits
class Foo extends Bar {
   constructor (x, y, z) { ... }
}

P.S.: Scala e.g. uses a similar approach. But they use `object' keyword 
when inheriting from objects:

object foo extends bar {
   ...
}

Though, they also may use `with' in this context:

object foo extends bar with baz {
   ...
}

thus baz is a mixin. The same with classes:

class Foo extends Bar with baz {
   ....
}

Dmitry.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111117/7eab699f/attachment.html>


More information about the es-discuss mailing list