ecmascript-proposal-first-class-protocol

 ecmascript-proposal-first-class-protocol

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

Transcript

  1. proposal-first-class-protocol

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

    ـؚٗ: http://abcdef.gets.b6n.ch/ Twitter: https://twitter.com/brn227 GitHub: https://github.com/brn
  3. What is this proposal ? protocolך䲿周 ⯋ղכinterfaceך䲿周׌׏׋կ

  4. What is 'protocol' ? classָ㹋鄲ׅץֹ鋉秈׾邌ׅկ 㹋䡾כקה׿וinterfaceהずׄדծ swiftװobjective-cדכinterface׾protocolהㄎןծ javaדכず瘝ך׮ך׾interfaceהㄎע(稢ְַ鎉铂➬圫♳ך麩ְכ֮ ׷ָ)

  5. Ecmascript way ׃ַ׃Ecmascriptךprotocolכֿך⚕倯ה׮殯ז׷杝荈ך➬圫ָ䲿 周ׁ׸גְ׷կ

  6. As Symbol 植㖈䲿周⚥ךֿךproposalכprotocol׾ծ ًاحس׾䭯אSymbolך꧊さה׃ג邌ׅկ

  7. protocol ProtocolName {! // 実装が必要なシンボルを宣言 thisMustBeImplemented;! ! // メソッド実装 youGetThisMethodForFree()

    {! return this[ProtocolName.thisMustBeImplemented]();! }! }! ! class ClassName implements ProtocolName {! [ProtocolName.thisMustBeImplemented]() {! ...! }! } !
  8. Extends Existing class 傀㶷ךclassח㼎׃ג׮protocol׾㹋鄲ׅ׷ֿהָדֹ׷կ

  9. protocol Functor {! map;! }! ! Promise.prototype[Functor.map] = () =>

    {! ...! }! ! Protocol.implement(Promise, Functor);!
  10. 'implements' keyword 倜׋חimplements怴皾㶨ָ鷄⸇ׁ׸׷

  11. Promise implements Functor // true! ! if (MyClass implements SomeProtocol)

    { }!
  12. Extends protocol protocolכ➭ךprotocol׾䭁䓸דֹ׷

  13. protocol A { a; }! protocol B extends A {

    b; }! ! class C implements B {! [A.a]() {}! [B.b]() {}! }! ! class D implements A {! [A.a]() {}! }!
  14. Default Implementation ⴱ劍㹋鄲׮鷄⸇דֹ׷

  15. protocol A { a; }! ! protocol B extends A

    {! [A.a]() { ... }! }!
  16. Static protocol ꫼涸ًاحس׮protocolדⵖ䖴ׅ׷ֿהָ〳腉

  17. protocol A {! static b() {}! }! ! class C

    implements A { }! C[A.b]();!
  18. Issues 傀㶷ךؙٓأ׾䭁䓸ׅ׷㜥さծprototypeפך湫䱸➿Ⰵהְֲ䲿周ָ 遤׻׸גְ׷կ ְֻ׵ז׿ד׮儗➿鹼׸זךדծ➿剏周׾䲿周׃גְֶ׋կ

  19. Proposed 1 Protocol.impelemtꟼ侧ך痥♲䒷侧ד㹋鄲

  20. protocol Functor {! map;! }! ! // If implementation is

    not satisfied, throw TypeError.! Protocol.implement(Array, Functor, {! [Functor.map]: Array.prototype.map! });!
  21. Proposed 2 傀㶷ךؙٓأ׮ⱄ䏝implementsؗ٦ٙ٦سד䭁䓸〳腉ח

  22. protocol Functor {! map;! }! ! // We can implements

    protocol after declaration.! Array implements Functor {! [Functor.map]: Array.prototype.map! }!
  23. TypeScript? ה׶ִ֮׆ծ傀㶷ךinterfaceכ婍ׅד֮׹ֲהךֿהկ protocol׾וך״ֲז㘗ה׃ג䪔ֲַכ劢㹀 Allow dynamic name in typesהְֲ㘗ךفٗػذ؍せחsymbol׾ ⢪ֲֿהָדֹ׷PRָ鹌׿דְ׷ךדծ ֿ׸ָ㹋鄲ׁ׸׷הprotocol׮أي٦ؤחְֽ׷ַ׮կ

  24. ׀幠耮֮׶ָהֲ׀ְׂת׃׋