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
800
プロダクト開発とTypeScript
brn
8
2.8k
React-Springでリッチなアニメーション
brn
1
620
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
95
5.2k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Mobile First: as difficult as doing things right
swwweet
222
9k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
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·ͰோΊͯΈ·ͨ͠ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠