Finding a "safety syntax" for classes

Russell Leggett russell.leggett at gmail.com
Wed Mar 21 11:28:25 PDT 2012


On Wed, Mar 21, 2012 at 2:25 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:

>
> On Mar 21, 2012, at 6:25 AM, Russell Leggett wrote:
>
>
> ...
>
> Yeah - that is the way I was leaning, partly because I like it, and partly
> because that was the behavior in <| for functions in the class pattern. I
> think it could help make it easier for people to fill the gaps in the
> minimal syntax. For example, many class libs have some mixin functionality.
> If mixin were added to a custom base class, then you could do:
>
>     class Foo extends MyBase {
>         ...
>     }.mixin(enumerable);
>
>
> There are likely issue with the above syntax.  However, I can imagine
> someway saying:
>
> class Foo extends mixin(MyBase, enumerable) {
> }
>
> where mixin is defined as:
>
> function mixin(directSuper, ...mixins) {
>     let effectiveSuper = class extends directSuper{ constructor(...args)
> {return super.constructor(...args)}};
>     for (let m of mixins) Object.extend(effectiveSuper.proto,mixins);
>  //probably need some conflict resolution logic
>     return effectiveSuper
> }
>

hmmm... yeah, I like this a lot, actually.



>
> Allen
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120321/673241b7/attachment-0001.html>


More information about the es-discuss mailing list