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
6
2.8k
Parsing Javascript
brn
12
8.5k
JSON & Object Tips
brn
1
350
CA 1Day Youth Bootcamp for Frontend LT
brn
0
740
Modern TypeScript
brn
2
720
javascript - behind the scene
brn
3
660
tc39 proposals
brn
0
740
プロダクト開発とTypeScript
brn
8
2.8k
React-Springでリッチなアニメーション
brn
1
560
Other Decks in Programming
See All in Programming
Amebaチョイス立ち上げの裏側 ~依存システムとの闘い~
daichi_igarashi
0
220
私のEbitengineの第一歩
qt_luigi
0
420
私の考える初学者がBlazorできるまでの学習方法
tomokusaba
1
250
マイグレーションコード自作して File-Based Routing に自動移行!! ~250 ページの歴史的経緯を添えて~
cut0
1
250
Meet BrowserEngineKit
swiftty
0
260
現代のVueとTypeScript - 型安全の活用術
minako__ph
4
3.1k
iOSDC 2024 SMBファイル共有をSwiftで実装する
kishikawakatsumi
1
110
メモリ最適化を究める!iOSアプリ開発における5つの重要なポイント
yhirakawa333
0
380
Ebitengineの1vs1ゲーム WebRTCの活用
ponyo877
0
350
複雑さに立ち向かうための ソフトウェア開発入門
shiz
3
620
Regular Expressions, REXML, Automata Learning
makenowjust
0
190
Rubyのobject_id
qnighy
6
1.3k
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
22
3.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
263
13k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
26
1.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
400
65k
Agile that works and the tools we love
rasmusluckow
327
20k
Bash Introduction
62gerente
608
210k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
27
1.6k
Building Better People: How to give real-time feedback that sticks.
wjessup
359
18k
The Mythical Team-Month
searls
218
43k
4 Signs Your Business is Dying
shpigford
179
21k
A Modern Web Designer's Workflow
chriscoyier
690
190k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
25
1.3k
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أي٦ؤחְַֽկ
׀幠耮ָ֮הֲ׀ְׂת׃