Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JavaScriptだってプライベートがほしい
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kaneko Takeshi
August 02, 2019
Technology
59
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JavaScriptだってプライベートがほしい
Kaneko Takeshi
August 02, 2019
More Decks by Kaneko Takeshi
See All by Kaneko Takeshi
オープンソースライセンスについて勉強する定期
tkckaneko
0
49
Eye Tracking on the Browser
tkckaneko
0
100
IEEE754を完全に理解した
tkckaneko
1
89
CSSのトレンドをみんなで見よう -2021年-
tkckaneko
0
100
多分これが一番早いと思います
tkckaneko
0
31
暗黒面の話
tkckaneko
0
31
CSR / SSR / SSG / JAMstack
tkckaneko
0
79
BOLT
tkckaneko
0
43
CSS Logical Properties and Values
tkckaneko
0
65
Other Decks in Technology
See All in Technology
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
0
320
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
230
味覇で作るパスタが美味い - 20261001_yabaubuki.dev
livesense
PRO
0
130
自主式軟體工廠
philipz
0
260
会社説明資料
persolserverworks
0
9.7k
12 個 Tool と、 4,096 Token
hlum
0
140
AgentCoreで実践するハーネスエンジニアリング
yakumo
1
300
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.2k
Post AI時代のリファクタリング実践記 / Refactoring in the post AI era
kaminashi
1
180
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
270
生成AIで高い生産性を求められて、 悩み、乗り越えた話
mot_techtalk
2
170
事業成長とデータ活用を止めないためのマネジメントへ挑戦
hiracky16
0
320
Featured
See All Featured
Facilitating Awesome Meetings
lara
57
7.2k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
530
Navigating Team Friction
lara
192
16k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
360
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
980
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Transcript
JavaScriptだってプライベートがほしい
あ・・・ありのまま ES2018の仕様を話すぜ! 「JavaScriptにはPrivate Class Fieldがない」 な・・・ 何を言っているのか わからねーと思うが おれも 何を言ってるのか わからなかった・・・ 頭がどうにかなりそうだった・・・ ReactだとかTypeScriptだとか
そんなチャチなもんじゃあ 断じてねえ もっと恐ろしいものの片鱗を 味わったぜ・・・
そもそもJavaScriptにClassがないじゃん? って思われるかもしれませんが ES2015でクラス構文が定義されました
ただし、オブジェクト指向継承モデルを導入したわけではありません プロトタイプベース継承の糖衣構文です 「特別な関数」という扱いです なので、クラス式という書き方もできます
例) let Rectangle = class { constructor(height, width) { this.height
= height; this.width = width; } calcArea() { return this.height * this.width; } };
初期段階では他の言語では標準である機能については めんどくさかったのか、あと回しになってました(議論はしてた?) なので先程のクラスの変数はすべてpublicです
例) class Engineer { constructer(name, type) { this.name = name;
this.type = type; } speak() { console.log(`${this.name} is ${this.type} Engineer.`) } } const kaneko = new Engineer('Kaneko', 'Front End'); kaneko.speak(); / / Kaneko is Front End Engineer. kaneko.type = 'Unity'; kaneko.speak(); / / Kaneko is Unity Engineer.
None
JavaScriptにもPrivate Class Fieldを 求める声は2017年になってproposalとなりました https:/ /github.com/tc39/proposal-class-fields それまではいろんな手段をつかってきました
例1) 運用でカバー 公開を意図しないフィールドには _ をつけるなど const Engineer = ((name, type)
=> { constructer(name, type) { this._name = name; this._type = type; } speak() { console.log(`${this._name} is ${this._type} Engineer.`) } })
例2)Soft Private const Engineer = ((name, type) => { const
privateName = Symbol() const privateType = Symbol() return class EngineerClass { constructor(name, type) { this[privateName] = name; this[privateType] = type; } speak() { console.log(`${this[privateName]} is ${this[privateType]} Engineer.`) } } })()
ようやくproposalがStage 3になりました! Chrome 74で実装済みです!
例) class Engineer { #name = ''; #type = '';
constructer(name, type) { this.#name = name; this.#type = type; } speak() { console.log(`${this.#name} is ${this.#type} Engneer.`) } } const kaneko = new Engineer('Kaneko', 'Front End'); kaneko.speak(); / / Kaneko is Front End Engineer. kaneko.#type = 'Unity'; / / SyntaxError kaneko.speak(); / / Kaneko is Front End Engineer.
この#を使った構文にたどり着くまでに 紆余曲折がありました 2年もかかりました
JavaScriptでもprivateを使おうとしてたのか 予約語にはなってます しかしJavaScriptでは動的にプロパティが定義できるため 毎回、privateなのかpublicなのか判定する必要が出てきてしまいます
例) class Engineer { private name = '' private type
= '' constructer(name, type) { this.name = name; this.type = type; } } consta kaneko = new Engineer('kaneko', 'Front End'); kaneko.type = 'Unity'; / / public変数として定義される kaneko.speak(); / / Kaneko is Front End Engineer.
#以外の記号も検討されましたが ASI hazardsやshorthandなどを考慮して却下されました
こうしてJavaScriptは2019年になって 念願のプライベートを手に入れるかもしれません (まだStage 3)