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
2k
Parsing Javascript
brn
12
6.8k
JSON & Object Tips
brn
1
280
CA 1Day Youth Bootcamp for Frontend LT
brn
0
660
Modern TypeScript
brn
2
670
javascript - behind the scene
brn
3
590
tc39 proposals
brn
0
630
プロダクト開発とTypeScript
brn
8
2.7k
React-Springでリッチなアニメーション
brn
1
480
Other Decks in Programming
See All in Programming
C#でのPlaywrightを使ったE2Eテストの実際
tomokusaba
0
210
PHPerKaigi 2024〜10年以上動いているレガシーなバッチシステムを Kubernetes(Amazon EKS) に移行する取り組み〜
tshinowpub
1
170
プログラミングを楽しもう! / Enjoy Programming
chobishiba
1
700
架空のコンペ_スクワットフォーム判別コンペの解法
cpptake
0
430
「プログラマーのためのCPU入門」は入り口として丁度よい!
forrep
25
22k
Reckoner の Scala プロジェクトにおける オブザーバビリティの取り組み / Observability Initiatives in Reckoner's Scala Project
nomadblacky
0
820
sbt-assemblyにハマってDB接続できず時間が溶けた話
wakye5815
1
660
Running Laravel Apps With FrankenPHP
dunglas
4
1.2k
一休.comレストランのRustバックエンド開発の様子
kymmt90
13
7.9k
CSRF対策のやり方、そろそろアップデートしませんか / Update your knowledge of CSRF protection
hiro_y
22
12k
Flutterアプリを GitHub Actions & Xcode Cloud で社内配布する / Distribute Flutter apps internally
takasfz
0
130
見せ算をScalaで実装してみた / Scalaわいわい勉強会 #2
arthur1
0
1.1k
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
4
1.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
319
23k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
242
20k
Designing for humans not robots
tammielis
247
25k
GraphQLの誤解/rethinking-graphql
sonatard
48
9.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
113
18k
Optimizing for Happiness
mojombo
369
69k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
28
5.9k
Being A Developer After 40
akosma
56
580k
Optimising Largest Contentful Paint
csswizardry
7
2.3k
Learning to Love Humans: Emotional Interface Design
aarron
266
39k
Statistics for Hackers
jakevdp
789
220k
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أي٦ؤחְַֽկ
׀幠耮ָ֮הֲ׀ְׂת׃