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.7k
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
6
3k
Parsing Javascript
brn
13
9.1k
JSON & Object Tips
brn
1
440
CA 1Day Youth Bootcamp for Frontend LT
brn
0
870
Modern TypeScript
brn
2
770
javascript - behind the scene
brn
3
710
tc39 proposals
brn
0
820
プロダクト開発とTypeScript
brn
8
2.8k
React-Springでリッチなアニメーション
brn
1
650
Other Decks in Programming
See All in Programming
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
170
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
12
4k
1年目の私に伝えたい!テストコードを怖がらなくなるためのヒント/Tips for not being afraid of test code
push_gawa
0
200
DROBEの生成AI活用事例 with AWS
ippey
0
130
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
140
昭和の職場からアジャイルの世界へ
kumagoro95
1
380
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
130
SpringBoot3.4の構造化ログ #kanjava
irof
2
1k
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
5
390
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
3
750
Amazon S3 TablesとAmazon S3 Metadataを触ってみた / 20250201-jawsug-tochigi-s3tables-s3metadata
kasacchiful
0
170
SwiftUI Viewの責務分離
elmetal
PRO
1
240
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Speed Design
sergeychernyshev
27
790
Building Applications with DynamoDB
mza
93
6.2k
Navigating Team Friction
lara
183
15k
The Cult of Friendly URLs
andyhume
78
6.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
630
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
51k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Fireside Chat
paigeccino
34
3.2k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
330
Gamification - CAS2011
davidbonilla
80
5.1k
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أي٦ؤחְַֽկ
׀幠耮ָ֮הֲ׀ְׂת׃