Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ecmascript-proposal-first-class-protocol

 ecmascript-proposal-first-class-protocol

EcmascriptのFirst class protocolの提案について

More Decks by Taketoshi Aono(青野健利 a.k.a brn)

Other Decks in Programming

Transcript

  1. せ⵸: @brn (ꫬꅿ⨳ⵃa.k.a ـٕ٦ظ) 耵噟: ؿٗٝزؒٝسؒٝآص،٥iOSؒٝآص، ⠓爡: Cyberagent ،سذؙأةآؔRightSegment٥AI Messenger

    ـؚٗ: http://abcdef.gets.b6n.ch/ Twitter: https://twitter.com/brn227 GitHub: https://github.com/brn
  2. protocol ProtocolName {! // 実装が必要なシンボルを宣言 thisMustBeImplemented;! ! // メソッド実装 youGetThisMethodForFree()

    {! return this[ProtocolName.thisMustBeImplemented]();! }! }! ! class ClassName implements ProtocolName {! [ProtocolName.thisMustBeImplemented]() {! ...! }! } !
  3. protocol Functor {! map;! }! ! Promise.prototype[Functor.map] = () =>

    {! ...! }! ! Protocol.implement(Promise, Functor);!
  4. protocol A { a; }! protocol B extends A {

    b; }! ! class C implements B {! [A.a]() {}! [B.b]() {}! }! ! class D implements A {! [A.a]() {}! }!
  5. protocol A {! static b() {}! }! ! class C

    implements A { }! C[A.b]();!
  6. protocol Functor {! map;! }! ! // If implementation is

    not satisfied, throw TypeError.! Protocol.implement(Array, Functor, {! [Functor.map]: Array.prototype.map! });!
  7. protocol Functor {! map;! }! ! // We can implements

    protocol after declaration.! Array implements Functor {! [Functor.map]: Array.prototype.map! }!