Kevin Smith (2014-02-13T23:34:22.000Z)
domenic at domenicdenicola.com (2014-02-18T04:39:27.458Z)
> 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. } }; } }