Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
ecmascript-proposal-first-class-protocol
Taketoshi Aono(青野健利 a.k.a brn)
October 06, 2017
Programming
0
1.3k
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)
CA 1Day Youth Bootcamp for Frontend LT
brn
0
230
Modern TypeScript
brn
2
540
javascript - behind the scene
brn
3
450
tc39 proposals
brn
0
470
プロダクト開発とTypeScript
brn
8
2.4k
React-Springでリッチなアニメーション
brn
1
410
javascript internationalization API
brn
0
490
How V8 executes WASM
brn
3
1.3k
memory_in_javascript.pdf
brn
0
650
Other Decks in Programming
See All in Programming
IE Graduation (IE の功績を讃える)
jxck
20
12k
Scrum Fest Osaka 2022/5年で200人になったスタートアップの アジャイル開発の歴史とリアル
atamaplus
1
940
iOS 16からのロック画面Widget争奪戦に備える
tsuzuki817
0
250
Node.jsデザインパターンを読んで
mmmommm
0
2.8k
設計の学び方:自分流のススメ
masuda220
PRO
10
7.3k
Baseline Profilesでアプリのパフォーマンスを向上させる / Improve app performance with Baseline Profiles
numeroanddev
0
250
VisualProgramming_GoogleHome_LINE
nearmugi
1
230
engineer
spacemarket
0
3.8k
Get Ready for Jakarta EE 10
ivargrimstad
0
2.7k
GoogleI/O2022 LT報告会資料
shinsukefujita1126
0
380
Let's keep Commodore 64 alive for the next 40 years
mehowte
1
110
Reactは何を提供するLibraryなのか?
taro28
3
510
Featured
See All Featured
BBQ
matthewcrist
74
7.9k
Infographics Made Easy
chrislema
233
17k
How to name files
jennybc
40
61k
Writing Fast Ruby
sferik
612
57k
No one is an island. Learnings from fostering a developers community.
thoeni
9
1.3k
Pencils Down: Stop Designing & Start Developing
hursman
112
9.8k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_i
23
15k
jQuery: Nuts, Bolts and Bling
dougneiner
56
6.4k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
212
20k
Raft: Consensus for Rubyists
vanstee
126
5.4k
Code Reviewing Like a Champion
maltzj
506
37k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
5
510
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أي٦ؤחְַֽկ
׀幠耮ָ֮הֲ׀ְׂת׃