Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ecmascript-proposal-first-class-protocol
Search
Taketoshi Aono(青野健利 a.k.a brn)
October 06, 2017
Programming
0
1.6k
ecmascript-proposal-first-class-protocol
EcmascriptのFirst class protocolの提案について
Taketoshi Aono(青野健利 a.k.a brn)
October 06, 2017
Tweet
Share
More Decks by Taketoshi Aono(青野健利 a.k.a brn)
See All by Taketoshi Aono(青野健利 a.k.a brn)
document.write再考
brn
5
2.5k
Parsing Javascript
brn
12
6.9k
JSON & Object Tips
brn
1
280
CA 1Day Youth Bootcamp for Frontend LT
brn
0
660
Modern TypeScript
brn
2
680
javascript - behind the scene
brn
3
590
tc39 proposals
brn
0
640
プロダクト開発とTypeScript
brn
8
2.7k
React-Springでリッチなアニメーション
brn
1
490
Other Decks in Programming
See All in Programming
Compiling Python to WebAssembly with py2wasm
syrusakbary
0
140
Kotlinを用いたDSL的な設計手法と使用上の注意
kohii00
3
530
クソコード動画『カプセル化 Mk-II』 で考える 上手くカプセル化できない理由 / encapsulation2
minodriven
11
8k
生成 AI の中身を覗いてみよう〜基礎から医療現場での応用まで〜
soh9834
2
770
決断するための勇気、そのためのBacklog / Courage to make decisions, Backlog for that.
seike460
PRO
4
1.9k
Laravel標準バリデーションでできること
hmb_ok
2
360
WasmOS: Wasmを実行する自作Microkernel
riru
0
370
オブジェクト指向コードレビューの新しいアプローチ
akkie76
3
1.5k
PHPでOfficeファイルを取り扱う! PHP Officeライブラリを プロダクトに組み込んだ話
hirobe1999
0
840
フロントエンドパフォーマンス 入門
shouta2
7
1.5k
オブジェクトしこう
okuramasafumi
2
130
Some Quick Ideas To Improve Your Tests ( #jassttokyo )
teyamagu
PRO
2
2.3k
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
48
9.1k
Rebuilding a faster, lazier Slack
samanthasiow
72
8.2k
Designing for humans not robots
tammielis
247
25k
Bash Introduction
62gerente
604
210k
How GitHub (no longer) Works
holman
301
140k
BBQ
matthewcrist
78
8.7k
Product Roadmaps are Hard
iamctodd
43
9.6k
How to train your dragon (web standard)
notwaldorf
71
5.1k
Adopting Sorbet at Scale
ufuk
66
8.5k
Fontdeck: Realign not Redesign
paulrobertlloyd
75
4.8k
4 Signs Your Business is Dying
shpigford
174
21k
Making the Leap to Tech Lead
cromwellryan
123
8.4k
Transcript
proposal-first-class-protocol
せ: @brn (ꫬꅿ⨳ⵃa.k.a ـٕ٦ظ) 耵噟: ؿٗٝزؒٝسؒٝآص،٥iOSؒٝآص، ⠓爡: Cyberagent ،سذؙأةآؔRightSegment٥AI Messenger
ـؚٗ: http://abcdef.gets.b6n.ch/ Twitter: https://twitter.com/brn227 GitHub: https://github.com/brn
What is this proposal ? protocolך䲿周 ⯋ղכinterfaceך䲿周կ
What is 'protocol' ? classָ㹋鄲ׅץֹ鋉秈邌ׅկ 㹋䡾כקהוinterfaceהずׄדծ swiftװobjective-cדכinterfaceprotocolהㄎןծ javaדכず瘝ךךinterfaceהㄎע(稢ְַ鎉铂➬圫♳ך麩ְכ֮ ָ)
Ecmascript way ׃ַ׃Ecmascriptךprotocolכֿך⚕倯ה殯ז杝荈ך➬圫ָ䲿 周ׁגְկ
As Symbol 植㖈䲿周⚥ךֿךproposalכprotocolծ ًاحس䭯אSymbolך꧊さה׃ג邌ׅկ
protocol ProtocolName {! // 実装が必要なシンボルを宣言 thisMustBeImplemented;! ! // メソッド実装 youGetThisMethodForFree()
{! return this[ProtocolName.thisMustBeImplemented]();! }! }! ! class ClassName implements ProtocolName {! [ProtocolName.thisMustBeImplemented]() {! ...! }! } !
Extends Existing class 傀㶷ךclassח㼎׃גprotocol㹋鄲ֿׅהָדֹկ
protocol Functor {! map;! }! ! Promise.prototype[Functor.map] = () =>
{! ...! }! ! Protocol.implement(Promise, Functor);!
'implements' keyword 倜חimplements怴皾㶨ָ鷄⸇ׁ
Promise implements Functor // true! ! if (MyClass implements SomeProtocol)
{ }!
Extends protocol protocolכ➭ךprotocol䭁䓸דֹ
protocol A { a; }! protocol B extends A {
b; }! ! class C implements B {! [A.a]() {}! [B.b]() {}! }! ! class D implements A {! [A.a]() {}! }!
Default Implementation ⴱ劍㹋鄲鷄⸇דֹ
protocol A { a; }! ! protocol B extends A
{! [A.a]() { ... }! }!
Static protocol 涸ًاحسprotocolדⵖ䖴ֿׅהָ〳腉
protocol A {! static b() {}! }! ! class C
implements A { }! C[A.b]();!
Issues 傀㶷ךؙٓأ䭁䓸ׅ㜥さծprototypeפך湫䱸➿Ⰵהְֲ䲿周ָ 遤גְկ ְֻזד儗➿鹼זךדծ➿剏周䲿周׃גְֶկ
Proposed 1 Protocol.impelemtꟼ侧ך痥♲䒷侧ד㹋鄲
protocol Functor {! map;! }! ! // If implementation is
not satisfied, throw TypeError.! Protocol.implement(Array, Functor, {! [Functor.map]: Array.prototype.map! });!
Proposed 2 傀㶷ךؙٓأⱄ䏝implementsؗ٦ٙ٦سד䭁䓸〳腉ח
protocol Functor {! map;! }! ! // We can implements
protocol after declaration.! Array implements Functor {! [Functor.map]: Array.prototype.map! }!
TypeScript? הִ֮׆ծ傀㶷ךinterfaceכ婍ׅדֲ֮הךֿהկ protocolוך״ֲז㘗ה׃ג䪔ֲַכ劢㹀 Allow dynamic name in typesהְֲ㘗ךفٗػذ؍せחsymbol ⢪ֲֿהָדֹPRָ鹌דְךדծ ָֿ㹋鄲ׁהprotocolأي٦ؤחְַֽկ
׀幠耮ָ֮הֲ׀ְׂת׃