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
770
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
410
CA 1Day Youth Bootcamp for Frontend LT
brn
0
820
Modern TypeScript
brn
2
750
javascript - behind the scene
brn
3
690
tc39 proposals
brn
0
790
プロダクト開発とTypeScript
brn
8
2.8k
React-Springでリッチなアニメーション
brn
1
620
Featured
See All Featured
The Cult of Friendly URLs
andyhume
78
6.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
How to Ace a Technical Interview
jacobian
276
23k
Documentation Writing (for coders)
carmenintech
66
4.5k
Producing Creativity
orderedlist
PRO
341
39k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
How GitHub (no longer) Works
holman
311
140k
GitHub's CSS Performance
jonrohan
1030
460k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
We Have a Design System, Now What?
morganepeng
51
7.3k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
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·ͰோΊͯΈ·ͨ͠ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠