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
740
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.8k
Parsing Javascript
brn
12
8.8k
JSON & Object Tips
brn
1
370
CA 1Day Youth Bootcamp for Frontend LT
brn
0
760
Modern TypeScript
brn
2
730
javascript - behind the scene
brn
3
670
tc39 proposals
brn
0
760
プロダクト開発とTypeScript
brn
8
2.8k
React-Springでリッチなアニメーション
brn
1
580
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
509
110k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
26
4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
24
1.7k
Speed Design
sergeychernyshev
22
480
Navigating Team Friction
lara
183
14k
For a Future-Friendly Web
brad_frost
174
9.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
3
220
How To Stay Up To Date on Web Technology
chriscoyier
787
250k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
130k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
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·ͰோΊͯΈ·ͨ͠ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠