>
>
> I remember it was discussed here
> http://esdiscuss.org/topic/protocol-library-as-alternative-to-refinements-russell-leggett,
>   ( the syntax in
> https://gist.github.com/genericallyloud/7086380 )
>
> Do the semantics proposed above work with what's proposed there?
>

That's it - thanks for the link!

Yes - it could definitely work.  Russell didn't actually an implementation
for the his Protocol function, but using this proposal, the "methods"
property of the resulting "protocol" object could be a dictionary of custom
"reference name" objects.

Leaving aside all of the gory dispatch details, it might look something
like this:

    class Protocol {

        constructor(...names) {

            this.methods = {};

            for (let name of names)
                this.methods[name] = this._createMethod(name);
        }

        _createMethod(name) {

            return {

                [Symbol.referenceGet]: target => {

                    // 1. If target has an own property of "name", return
it.
                    // 2. If target's type matches an extension of the
protocol,
                    //    return the protocol method.
                    // 3. If the target has a method of the same name
somewhere up
                    //    the prototype chain, return it.
                    // 4. If a default has been defined, return it.
                    // 5. Otherwise, return undefined.
                }

            };
        }
    }
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to