SlideShare a Scribd company logo
1 of 18
Tommy Lin
林儀泰
FB/Email:tooto1985@gmail.com
 傳值參考(call by value)
◦ 複製內容到新的參照上。
 傳址參考(call by reference)
◦ 引用參考到新的參照上,修改或賦予新值都會改變原有參
照。
 共享參考(call by sharing)
◦ 複製參考到新的參照上,修改會改變原有參照,但賦予新
值則會產生新的參考。
 傳值參考(call by value)
◦ 複製內容到新的參照上。
 傳址參考(call by reference)
◦ 引用參考到新的參照上,修改或賦予新值都會改變原有參
照。
 共享參考(call by sharing)
◦ 複製參考到新的參照上,修改會改變原有參照,但賦予新
值則會產生新的參考。
 為什麼看起來像傳值?
◦ 原始(primitive)型別是不可變(immutable)的,無法修改
值,永遠只能賦予新值。
 為什麼看起來像傳址?
◦ 物件(object)型別雖然是可變(mutable)的,修改會改變原
本參考,但賦予新值會產生新的參考。
◦ 我們常常忽略了”賦予新值會改變原有參考”這個定義
◦ 感覺好像是傳址參考 (實際上並不是喔)!
var aaa = “string”; RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
aaa
“string”
AddressVariable
0x01
var aaa = “string”;
function run(xyz) {
xyz=“world”;
}
RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
Address
run
function run…
Variable
aaa
“string”
0x01
0x03
var aaa = “string”;
function run(xyz) {
xyz=“world”;
}
run(aaa);
RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
Address
xyz
Variable
run
function run…
aaa
“string”
0x01
0x03
0x01
var aaa = “string”;
function run(xyz) {
xyz=“world”;
}
run(aaa);
RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
AddressVariable
xyz
run
function run…
aaa
“string”
0x01
0x03
0x06
“world”
var aaa = “string”;
function run(xyz) {
xyz=“world”;
}
run(aaa);
console.log(aaa);
RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
AddressVariable
xyz
run
function run…
aaa
“string”
0x01
0x03
0x06
“world”
var aaa = {name:”john”}; RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
aaa
{name:“john”}
AddressVariable
0x01
var aaa = {name:”john”};
function run(xyz) {
xyz.name=“mark”;
}
RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
Address
run
function run…
Variable
aaa
{name:“john”}
0x01
0x03
var aaa = {name:”john”};
function run(xyz) {
xyz.name=“mark”;
}
run(aaa);
RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
AddressVariable
run
function run…
aaa
{name:“john”}
0x01
0x03
xyz 0x01
var aaa = {name:”john”};
function run(xyz) {
xyz.name=“mark”;
}
run(aaa);
RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
AddressVariable
run
function run…
aaa
{name:“mark”}
0x01
0x03
xyz 0x01
var aaa = {name:”john”};
function run(xyz) {
xyz.name=“mark”;
}
run(aaa);
console.log(aaa);
RAM
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
AddressVariable
run
function run…
aaa
{name:“mark”}
0x01
0x03
xyz 0x01
 有一種類似傳值參考或傳址參考的錯覺
 但JavaScript中只有共享參考(call by sharing)一種
 http://www.ecma-international.org/ecma-262/5.1/#sec-8.7
 https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sh
aring
 http://www.codeproject.com/Articles/882622/An-
Illustrated-Guide-to-Parameter-Passing-in-JavaS
 http://www.jstips.co/en/know-the-passing-mechanism/
 http://bosn.me/js/js-call-by-sharing/

More Related Content

What's hot

Secure Virtual Private Cloud(VPC)를 활용한 보안성 강화와 비용절감 - 안경진 부장, 포티넷 코리아 :: AWS ...
Secure Virtual Private Cloud(VPC)를 활용한 보안성 강화와 비용절감 - 안경진 부장, 포티넷 코리아 :: AWS ...Secure Virtual Private Cloud(VPC)를 활용한 보안성 강화와 비용절감 - 안경진 부장, 포티넷 코리아 :: AWS ...
Secure Virtual Private Cloud(VPC)를 활용한 보안성 강화와 비용절감 - 안경진 부장, 포티넷 코리아 :: AWS ...Amazon Web Services Korea
 
Data Migration Using AWS Snowball, Snowball Edge & Snowmobile
Data Migration Using AWS Snowball, Snowball Edge & SnowmobileData Migration Using AWS Snowball, Snowball Edge & Snowmobile
Data Migration Using AWS Snowball, Snowball Edge & SnowmobileAmazon Web Services
 
AWS Application Migration Service-Hands-On Guide
AWS Application Migration Service-Hands-On GuideAWS Application Migration Service-Hands-On Guide
AWS Application Migration Service-Hands-On GuideManas Mondal
 
Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling ResolutionDEEPAK KHETAWAT
 
Amazon S3 & Amazon Glacier - Object Storage Overview
Amazon S3 & Amazon Glacier - Object Storage OverviewAmazon S3 & Amazon Glacier - Object Storage Overview
Amazon S3 & Amazon Glacier - Object Storage OverviewAmazon Web Services
 
20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...Amazon Web Services Japan
 
AWS S3 and GLACIER
AWS S3 and GLACIERAWS S3 and GLACIER
AWS S3 and GLACIERMahesh Raj
 
20200721 AWS Black Belt Online Seminar AWS App Mesh
20200721 AWS Black Belt Online Seminar AWS App Mesh20200721 AWS Black Belt Online Seminar AWS App Mesh
20200721 AWS Black Belt Online Seminar AWS App MeshAmazon Web Services Japan
 
A DIY Guide to Runbooks, Security Incident Reports, & Incident Response: AWS ...
A DIY Guide to Runbooks, Security Incident Reports, & Incident Response: AWS ...A DIY Guide to Runbooks, Security Incident Reports, & Incident Response: AWS ...
A DIY Guide to Runbooks, Security Incident Reports, & Incident Response: AWS ...Amazon Web Services
 
AWS re:Invent 2016: Workshop: AWS S3 Deep-Dive Hands-On Workshop: Deploying a...
AWS re:Invent 2016: Workshop: AWS S3 Deep-Dive Hands-On Workshop: Deploying a...AWS re:Invent 2016: Workshop: AWS S3 Deep-Dive Hands-On Workshop: Deploying a...
AWS re:Invent 2016: Workshop: AWS S3 Deep-Dive Hands-On Workshop: Deploying a...Amazon Web Services
 
Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Jukka Zitting
 
AWS Black Belt Online Seminar Elastic Load Balancing
AWS Black Belt Online Seminar Elastic Load BalancingAWS Black Belt Online Seminar Elastic Load Balancing
AWS Black Belt Online Seminar Elastic Load BalancingAmazon Web Services Japan
 
ABD201-Big Data Architectural Patterns and Best Practices on AWS
ABD201-Big Data Architectural Patterns and Best Practices on AWSABD201-Big Data Architectural Patterns and Best Practices on AWS
ABD201-Big Data Architectural Patterns and Best Practices on AWSAmazon Web Services
 
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...Amazon Web Services
 
AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)
AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)
AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)Amazon Web Services Korea
 
Amazon SageMaker 모델 배포 방법 소개::김대근, AI/ML 스페셜리스트 솔루션즈 아키텍트, AWS::AWS AIML 스페셜 웨비나
Amazon SageMaker 모델 배포 방법 소개::김대근, AI/ML 스페셜리스트 솔루션즈 아키텍트, AWS::AWS AIML 스페셜 웨비나Amazon SageMaker 모델 배포 방법 소개::김대근, AI/ML 스페셜리스트 솔루션즈 아키텍트, AWS::AWS AIML 스페셜 웨비나
Amazon SageMaker 모델 배포 방법 소개::김대근, AI/ML 스페셜리스트 솔루션즈 아키텍트, AWS::AWS AIML 스페셜 웨비나Amazon Web Services Korea
 
Best Practices for Implementing Your Encryption Strategy Using AWS Key Manage...
Best Practices for Implementing Your Encryption Strategy Using AWS Key Manage...Best Practices for Implementing Your Encryption Strategy Using AWS Key Manage...
Best Practices for Implementing Your Encryption Strategy Using AWS Key Manage...Amazon Web Services
 

What's hot (20)

Secure Virtual Private Cloud(VPC)를 활용한 보안성 강화와 비용절감 - 안경진 부장, 포티넷 코리아 :: AWS ...
Secure Virtual Private Cloud(VPC)를 활용한 보안성 강화와 비용절감 - 안경진 부장, 포티넷 코리아 :: AWS ...Secure Virtual Private Cloud(VPC)를 활용한 보안성 강화와 비용절감 - 안경진 부장, 포티넷 코리아 :: AWS ...
Secure Virtual Private Cloud(VPC)를 활용한 보안성 강화와 비용절감 - 안경진 부장, 포티넷 코리아 :: AWS ...
 
Data Migration Using AWS Snowball, Snowball Edge & Snowmobile
Data Migration Using AWS Snowball, Snowball Edge & SnowmobileData Migration Using AWS Snowball, Snowball Edge & Snowmobile
Data Migration Using AWS Snowball, Snowball Edge & Snowmobile
 
AWS Application Migration Service-Hands-On Guide
AWS Application Migration Service-Hands-On GuideAWS Application Migration Service-Hands-On Guide
AWS Application Migration Service-Hands-On Guide
 
Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling Resolution
 
Amazon S3 & Amazon Glacier - Object Storage Overview
Amazon S3 & Amazon Glacier - Object Storage OverviewAmazon S3 & Amazon Glacier - Object Storage Overview
Amazon S3 & Amazon Glacier - Object Storage Overview
 
20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
 
AWS S3 and GLACIER
AWS S3 and GLACIERAWS S3 and GLACIER
AWS S3 and GLACIER
 
20200721 AWS Black Belt Online Seminar AWS App Mesh
20200721 AWS Black Belt Online Seminar AWS App Mesh20200721 AWS Black Belt Online Seminar AWS App Mesh
20200721 AWS Black Belt Online Seminar AWS App Mesh
 
A DIY Guide to Runbooks, Security Incident Reports, & Incident Response: AWS ...
A DIY Guide to Runbooks, Security Incident Reports, & Incident Response: AWS ...A DIY Guide to Runbooks, Security Incident Reports, & Incident Response: AWS ...
A DIY Guide to Runbooks, Security Incident Reports, & Incident Response: AWS ...
 
Object storage
Object storageObject storage
Object storage
 
AWS re:Invent 2016: Workshop: AWS S3 Deep-Dive Hands-On Workshop: Deploying a...
AWS re:Invent 2016: Workshop: AWS S3 Deep-Dive Hands-On Workshop: Deploying a...AWS re:Invent 2016: Workshop: AWS S3 Deep-Dive Hands-On Workshop: Deploying a...
AWS re:Invent 2016: Workshop: AWS S3 Deep-Dive Hands-On Workshop: Deploying a...
 
Messaging in the AWS Cloud
Messaging in the AWS CloudMessaging in the AWS Cloud
Messaging in the AWS Cloud
 
Becoming an IAM Policy Ninja
Becoming an IAM Policy NinjaBecoming an IAM Policy Ninja
Becoming an IAM Policy Ninja
 
Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3
 
AWS Black Belt Online Seminar Elastic Load Balancing
AWS Black Belt Online Seminar Elastic Load BalancingAWS Black Belt Online Seminar Elastic Load Balancing
AWS Black Belt Online Seminar Elastic Load Balancing
 
ABD201-Big Data Architectural Patterns and Best Practices on AWS
ABD201-Big Data Architectural Patterns and Best Practices on AWSABD201-Big Data Architectural Patterns and Best Practices on AWS
ABD201-Big Data Architectural Patterns and Best Practices on AWS
 
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
 
AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)
AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)
AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)
 
Amazon SageMaker 모델 배포 방법 소개::김대근, AI/ML 스페셜리스트 솔루션즈 아키텍트, AWS::AWS AIML 스페셜 웨비나
Amazon SageMaker 모델 배포 방법 소개::김대근, AI/ML 스페셜리스트 솔루션즈 아키텍트, AWS::AWS AIML 스페셜 웨비나Amazon SageMaker 모델 배포 방법 소개::김대근, AI/ML 스페셜리스트 솔루션즈 아키텍트, AWS::AWS AIML 스페셜 웨비나
Amazon SageMaker 모델 배포 방법 소개::김대근, AI/ML 스페셜리스트 솔루션즈 아키텍트, AWS::AWS AIML 스페셜 웨비나
 
Best Practices for Implementing Your Encryption Strategy Using AWS Key Manage...
Best Practices for Implementing Your Encryption Strategy Using AWS Key Manage...Best Practices for Implementing Your Encryption Strategy Using AWS Key Manage...
Best Practices for Implementing Your Encryption Strategy Using AWS Key Manage...
 

簡單介紹JavaScript參數傳遞

  • 2.  傳值參考(call by value) ◦ 複製內容到新的參照上。  傳址參考(call by reference) ◦ 引用參考到新的參照上,修改或賦予新值都會改變原有參 照。  共享參考(call by sharing) ◦ 複製參考到新的參照上,修改會改變原有參照,但賦予新 值則會產生新的參考。
  • 3.  傳值參考(call by value) ◦ 複製內容到新的參照上。  傳址參考(call by reference) ◦ 引用參考到新的參照上,修改或賦予新值都會改變原有參 照。  共享參考(call by sharing) ◦ 複製參考到新的參照上,修改會改變原有參照,但賦予新 值則會產生新的參考。
  • 4.  為什麼看起來像傳值? ◦ 原始(primitive)型別是不可變(immutable)的,無法修改 值,永遠只能賦予新值。  為什麼看起來像傳址? ◦ 物件(object)型別雖然是可變(mutable)的,修改會改變原 本參考,但賦予新值會產生新的參考。 ◦ 我們常常忽略了”賦予新值會改變原有參考”這個定義 ◦ 感覺好像是傳址參考 (實際上並不是喔)!
  • 5.
  • 6. var aaa = “string”; RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 aaa “string” AddressVariable 0x01
  • 7. var aaa = “string”; function run(xyz) { xyz=“world”; } RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 Address run function run… Variable aaa “string” 0x01 0x03
  • 8. var aaa = “string”; function run(xyz) { xyz=“world”; } run(aaa); RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 Address xyz Variable run function run… aaa “string” 0x01 0x03 0x01
  • 9. var aaa = “string”; function run(xyz) { xyz=“world”; } run(aaa); RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 AddressVariable xyz run function run… aaa “string” 0x01 0x03 0x06 “world”
  • 10. var aaa = “string”; function run(xyz) { xyz=“world”; } run(aaa); console.log(aaa); RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 AddressVariable xyz run function run… aaa “string” 0x01 0x03 0x06 “world”
  • 11.
  • 12. var aaa = {name:”john”}; RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 aaa {name:“john”} AddressVariable 0x01
  • 13. var aaa = {name:”john”}; function run(xyz) { xyz.name=“mark”; } RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 Address run function run… Variable aaa {name:“john”} 0x01 0x03
  • 14. var aaa = {name:”john”}; function run(xyz) { xyz.name=“mark”; } run(aaa); RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 AddressVariable run function run… aaa {name:“john”} 0x01 0x03 xyz 0x01
  • 15. var aaa = {name:”john”}; function run(xyz) { xyz.name=“mark”; } run(aaa); RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 AddressVariable run function run… aaa {name:“mark”} 0x01 0x03 xyz 0x01
  • 16. var aaa = {name:”john”}; function run(xyz) { xyz.name=“mark”; } run(aaa); console.log(aaa); RAM 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 AddressVariable run function run… aaa {name:“mark”} 0x01 0x03 xyz 0x01
  • 18.  http://www.ecma-international.org/ecma-262/5.1/#sec-8.7  https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sh aring  http://www.codeproject.com/Articles/882622/An- Illustrated-Guide-to-Parameter-Passing-in-JavaS  http://www.jstips.co/en/know-the-passing-mechanism/  http://bosn.me/js/js-call-by-sharing/