javascriptの参照と値

 javascriptの参照と値

javascriptの参照渡しと値渡しについて

Transcript

  1. JAVASCRIPT REFERENCES & VALUES

  2. Name @brn (⻘野健利) Occupation フロントエンドエンジニア・ネイティブエンジニア Company Cyberagent アドテクスタジオ AI Messenger

    OSS Contributor of V8 About http://info.b6n.ch
  3. References and Values ࢀর ஋

  4. References and Values ஋ ஋ ࢀর ࢀর

  5. References and Values ࢀর͸ؒ઀తʹΦϒδΣΫτΛมߋ͢Δ ஋͸௚઀ͦͷΦϒδΣΫτΛมߋ͢Δ

  6. References or Values? KBWBTDSJQU͸ࢀরͱ஋ͷ྆ํΛ࢖͏ ΦϒδΣΫτຖʹͲ͏ѻΘΕΔ͔ܾ·͍ͬͯΔ

  7. Javascript object traits ࢀর "MMWBMVFTFYUFOET0CKFDU ஋ TUSJOH OVNCFS CPPMFBO

  8. Pass by reference/value const A = const B = ࢀর

    ஋ A = B = ஋
  9. Pass by reference const A = {}; const B =

    A; B.x = 1; console.log(A); // { x: 1 }
  10. Pass by value const A = 1; const B =

    A; B++; console.log(A); // 1
  11. Until here… ͱɺ͜͜·Ͱ͕Α͘ݴΘΕ͍ͯΔ ࠓճ͸΋͏ͪΐ͍ਂ۷Γͯ͠Έ͍ͨ

  12. Mutable, Immutable KBWBTDSJQUʹ͸ มߋՄೳͳ஋ͱมߋෆՄೳͳ஋͕͋Δ TUSJOH OVNCFS CPPMFBO͸มߋͰ͖ͳ͍

  13. Special cases OVNCFSͱCPPMFBO͸஋౉͠Ͱ͋Δ͜ͱ͕ଟ͍ ͨͩ͠TUSJOH͸৭ʑͳ޻෉͕͋Δέʔε͕ଟ͍ 7Ͱ͸TUSJOH͸ࢀরͱͳ͍ͬͯΔ

  14. 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;
  15. Immutablity make reference to value *NNVUBCMFͳจࣈྻ͕஋ͷΑ͏ʹৼΔ෣͏͕ ࣮ࡍʹ͸͢΂ͯࢀরΛ౉͍ͯ͠Δ

  16. What is reference? ࢀরͱ͸ͳΜͩΖ͏

  17. Pointer ΦϒδΣΫτ͸ੜ੒͞ΕΔͱώʔϓྖҬͱ͍͏ϝ ϞϦʹׂΓ౰ͯΒΕΔ ͦͷΦϒδΣΫτΛૢ࡞͢Δ৔߹͸ͦͷϝϞϦྖ ҬΛࢦࣔ͢͠ΞυϨεΛඞཁͱ͢Δ ͜Ε͕ϙΠϯλͱݺ͹ΕΔ΋ͷ

  18. Pointer is value KTΤϯδϯΛ࣮૷͍ͯ͠Δ$$ ͷੈքͰ͸ ϙΠϯλͦͷ΋ͷ΋·ͨ஋Ͱ͋Δ ͦͷͨΊϙΠϯλͷϙΠϯλΛ࡞ͬͨΓ΋Ͱ͖Δ

  19. Reference is value ͔͠͠KBWBTDSJQUͷੈքͰ͸ࢀরͷࢀর͸࡞Εͳ͍ ͭ·Γࢀর͸ৗʹ஋౉͠ͱͳΔ

  20. pass by copy reference ͭ·ΓKBWBTDSJQUͰ͸ ࢀর ϙΠϯλ Λ஋౉͍ͯ͠͠Δ ࢀরͷ஋౉͠ͱͳ͍ͬͯΔ

  21. Appendix 7಺෦ͷจࣈྻ࣮૷Λ؆୯ʹ

  22. String in V8 7Ͱ͸จࣈྻ͕ҎԼͷΫϥεʹ෼͔Ε͍ͯΔ 4FR0OF#ZUF4USJOH 4FR5XP#ZUF4USJOH $POT4USJOH 5IJO4USJOH 4MJDFE4USJOH

  23. String in V8 ಛʹTVCTUSJOHΛߦͬͨΓͯ͠ ৽ͨʹจࣈྻΠϯελϯεΛ࡞੒͢Δ৔߹ 3PQFͱ͍͏ΞϧΰϦζϜΛར༻ͨ͠ $POT4USJOH͕ར༻͞ΕΔ

  24. Rope จࣈྻͷ݁߹͕ߴ଎0 MPHO  ෼ׂ΋ߴ଎0 MPHO  औΓग़͠0 MPHO

  25. Rope 5PEBZJTXFBSFKBWBTDSJQUFS`T 5PEBZJT XFBSFKBWBTDSJQUFS`T 3005

  26. Rope 5PEBZJT 3005 8FBSF KBWBTDSJQUFS`T 53&&

  27. Summary ࢀরͱ஋͔Β3PQF·ͰோΊͯΈ·ͨ͠ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠