proposal-first-class-protocols
proposal-first-class-protocols copied to clipboard
a proposal to bring protocol-based interfaces to ECMAScript users
In [#43](https://github.com/tc39/proposal-first-class-protocols/issues/43#issuecomment-1542107331) I asked how the syntax for invoking protocols would look. The answer provided was: ```js stooges[Functor.map](stooge => stooge.toUpperCase()) ``` This is unpleasant to look at. I find it...
In the following, I make a case for why protocols are better realized using functions [instead of methods](https://github.com/tc39/proposal-first-class-protocols/issues/43#issuecomment-1594990013). **TLDR: Methods rely on classes/inheritance and provide static polymorphism, protocols dynamic polymorphism....
I've been using [a library](https://github.com/mlanza/atomic) I wrote for nearly a decade now where I implemented protocols as one of it's central premises, because I find them so useful in how...
As long as interfaces do not inherit from Object, is it possible to have them be cross realm?
I'm still struggling what problems this solves, can you help me enumerating some of the most compelling use cases this enables? You mentioned iter-ables/then-ables but this being a userland affordance,...
Hi, thanks for your work on this interesting proposal. Would be possible to initialize a protocol field by accessing `this`, or would that need to be a method? E.g.: ```javascript...
My suggestion for protocols ```ts // polyfill const protocol = (name: string, ...methods: string[]) => (() => { const symbols = Object.fromEntries(methods.map(key => [key, Symbol(`${name}.${key}`)])) return Object.assign( (Class: any, impl:...
Right now, this proposal shows how to make a public protocol that anyone can implement. There's also value in making it so only the creator of the protocol can control...
```ts protocol ToString { tag; toString() { return `[object ${this[ToString].tag}]`; } } Protocol.implement(Object, ToString); Object.prototype[ToString] = { tag: 'Object' }; // or Object.prototype[ToString].tag = 'Object'; ``` in #34 syntax ```ts...
I read the proposal a couple of times now, but I'm still failing to see who implementation selection is going to work. Let's say I create my own `ToString` protocol:...