protocol ProtocolName {
// declare a symbol which must be implemented
thisMustBeImplemented;
// and some methods that you get for free by implementing this protocol
youGetThisMethodForFree(...parameters) {
methodBody;
}
}
class ClassName implements ProtocolName {
[ProtocolName.thisMustBeImplemented]() {
// this is the implementation for this class
}
}
let instance = new ClassName;
instance[ProtocolName.youGetThisMethodForFree]();
Champion: @michaelficarra Repo: https://github.com/michaelficarra/proposal-first-class-protocols Slides: https://docs.google.com/presentation/d/1WrvSyslnF-5VnPj3k3HRq8MRzuiSN1kQ6ENE1iUSmDU/edit?usp=sharing First presented at the Sept 2017 meeting
Example
Implementation