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
javascriptの参照と値
Search
Taketoshi Aono(青野健利 a.k.a brn)
October 23, 2018
2
750
javascriptの参照と値
javascriptの参照渡しと値渡しについて
Taketoshi Aono(青野健利 a.k.a brn)
October 23, 2018
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.9k
Parsing Javascript
brn
12
9k
JSON & Object Tips
brn
1
400
CA 1Day Youth Bootcamp for Frontend LT
brn
0
790
Modern TypeScript
brn
2
750
javascript - behind the scene
brn
3
680
tc39 proposals
brn
0
780
プロダクト開発とTypeScript
brn
8
2.8k
React-Springでリッチなアニメーション
brn
1
600
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Optimizing for Happiness
mojombo
376
70k
Music & Morning Musume
bryan
46
6.2k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
What's in a price? How to price your products and services
michaelherold
243
12k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Visualization
eitanlees
145
15k
How STYLIGHT went responsive
nonsquared
95
5.2k
The Cult of Friendly URLs
andyhume
78
6k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Transcript
JAVASCRIPT REFERENCES & VALUES
Name @brn (⻘野健利) Occupation フロントエンドエンジニア・ネイティブエンジニア Company Cyberagent アドテクスタジオ AI Messenger
OSS Contributor of V8 About http://info.b6n.ch
References and Values ࢀর
References and Values ࢀর ࢀর
References and Values ࢀরؒతʹΦϒδΣΫτΛมߋ͢Δ ͦͷΦϒδΣΫτΛมߋ͢Δ
References or Values? KBWBTDSJQUࢀরͱͷ྆ํΛ͏ ΦϒδΣΫτຖʹͲ͏ѻΘΕΔ͔ܾ·͍ͬͯΔ
Javascript object traits ࢀর "MMWBMVFTFYUFOET0CKFDU TUSJOH OVNCFS CPPMFBO
Pass by reference/value const A = const B = ࢀর
A = B =
Pass by reference const A = {}; const B =
A; B.x = 1; console.log(A); // { x: 1 }
Pass by value const A = 1; const B =
A; B++; console.log(A); // 1
Until here… ͱɺ͜͜·Ͱ͕Α͘ݴΘΕ͍ͯΔ ࠓճ͏ͪΐ͍ਂ۷Γͯ͠Έ͍ͨ
Mutable, Immutable KBWBTDSJQUʹ มߋՄೳͳͱมߋෆՄೳͳ͕͋Δ TUSJOH OVNCFS CPPMFBOมߋͰ͖ͳ͍
Special cases OVNCFSͱCPPMFBO͠Ͱ͋Δ͜ͱ͕ଟ͍ ͨͩ͠TUSJOH৭ʑͳ͕͋Δέʔε͕ଟ͍ 7ͰTUSJOHࢀরͱͳ͍ͬͯΔ
String behave like value let A = 'a'; let B
= A; A += 'b' // Create new instance and assign to self. console.log(A); // 'ab'; console.log(B); // 'a;
Immutablity make reference to value *NNVUBCMFͳจࣈྻ͕ͷΑ͏ʹৼΔ͏͕ ࣮ࡍʹͯ͢ࢀরΛ͍ͯ͠Δ
What is reference? ࢀরͱͳΜͩΖ͏
Pointer ΦϒδΣΫτੜ͞ΕΔͱώʔϓྖҬͱ͍͏ϝ ϞϦʹׂΓͯΒΕΔ ͦͷΦϒδΣΫτΛૢ࡞͢Δ߹ͦͷϝϞϦྖ ҬΛࢦࣔ͢͠ΞυϨεΛඞཁͱ͢Δ ͜Ε͕ϙΠϯλͱݺΕΔͷ
Pointer is value KTΤϯδϯΛ࣮͍ͯ͠Δ$$ ͷੈքͰ ϙΠϯλͦͷͷ·ͨͰ͋Δ ͦͷͨΊϙΠϯλͷϙΠϯλΛ࡞ͬͨΓͰ͖Δ
Reference is value ͔͠͠KBWBTDSJQUͷੈքͰࢀরͷࢀর࡞Εͳ͍ ͭ·Γࢀরৗʹ͠ͱͳΔ
pass by copy reference ͭ·ΓKBWBTDSJQUͰ ࢀর ϙΠϯλ Λ͍ͯ͠͠Δ ࢀরͷ͠ͱͳ͍ͬͯΔ
Appendix 7෦ͷจࣈྻ࣮Λ؆୯ʹ
String in V8 7Ͱจࣈྻ͕ҎԼͷΫϥεʹ͔Ε͍ͯΔ 4FR0OF#ZUF4USJOH 4FR5XP#ZUF4USJOH $POT4USJOH 5IJO4USJOH 4MJDFE4USJOH
String in V8 ಛʹTVCTUSJOHΛߦͬͨΓͯ͠ ৽ͨʹจࣈྻΠϯελϯεΛ࡞͢Δ߹ 3PQFͱ͍͏ΞϧΰϦζϜΛར༻ͨ͠ $POT4USJOH͕ར༻͞ΕΔ
Rope จࣈྻͷ݁߹͕ߴ0 MPHO ׂߴ0 MPHO औΓग़͠0 MPHO
Rope 5PEBZJTXFBSFKBWBTDSJQUFS`T 5PEBZJT XFBSFKBWBTDSJQUFS`T 3005
Rope 5PEBZJT 3005 8FBSF KBWBTDSJQUFS`T 53&&
Summary ࢀরͱ͔Β3PQF·ͰோΊͯΈ·ͨ͠ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠