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
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Code Reviewing Like a Champion
maltzj
520
39k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Invisible Side of Design
smashingmag
298
50k
Building Applications with DynamoDB
mza
90
6.1k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Faster Mobile Websites
deanohume
305
30k
Fireside Chat
paigeccino
34
3k
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·ͰோΊͯΈ·ͨ͠ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠