Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
854 views
in Technique[技术] by (71.8m points)

typescript - Pass by Value and Pass by Reference in Javascript

Now that I've been working on Angular2 for almost 3 months, I've encountered a few scenarios which led me to wonder how does this happen ?

In the case of special this keyword it's obvious that it's passing a reference or instance of the related DOM Object or Class for Example.

But then there is another thing called ControlGroup which also does the same whenever it's assigned to another variable. And both the variables have access to same instance of that ControlGroup.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Objects and arrays are passed by reference. Primitive values like number, string, boolean are passed by value. A reference to an object is also a primitive type and passed by value like other primitive types, but the object it refers to is still passed by reference.

This is not Angular or TypeScript specific, just how JavaScript works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...