473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Assigment operator in JavaScript.

dmjpro
2,476 2GB
Have a look at my code snippet ....
Expand|Select|Wrap|Line Numbers
  1. function test(){
  2.     var obj = new Object();
  3.     obj.test = "Debasis Jana";
  4.     alert(obj.test);
  5.     var obj1 = obj;
  6.     obj1.test = "DMJPRO";
  7.     alert(obj.test);
  8. }
  9.  
Here assignment operates to copy the reference only. So changes to obj1 object makes changes to obj object.
But what i saw ...that if i copy the reference of a variable of child window to parent window variable ..after closing the child window how the parent variable exists ...?
i think after closing the window gets closed not the variables which bound to that window ... :-)

Debasis Jana
Aug 21 '08 #1
14 1386
r035198x
13,262 8TB
You have been here long enough to know that Java != Javascript.

<Moved>
Aug 21 '08 #2
dmjpro
2,476 2GB
You have been here long enough to know that Java != Javascript.

<Moved>
Sorry here i mistyped.... :-)
Aug 21 '08 #3
gits
5,390 Expert Mod 4TB
yes ... objects and arrays are passed by reference (simple types like boolean, strings, numbers and even functions are passed by value) ... and the reference points to the memory address ... all is 'bound' to the 'base-parent' window (not really but that is your current runtime environment if you like to see it that way), so if you store/pass a reference to something to this window then the garbage collector just knows that you have a reference to it and ignores that reference instead of throwing it ;)

kind regards
Aug 21 '08 #4
dmjpro
2,476 2GB
yes ... objects and arrays are passed by reference (simple types like boolean, strings, numbers and even functions are passed by value) ... and the reference points to the memory address ... all is 'bound' to the 'base-parent' window (not really but that is your current runtime environment if you like to see it that way), so if you store/pass a reference to something to this window then the garbage collector just knows that you have a reference to it and ignores that reference instead of throwing it ;)

kind regards
How functions and strings are passed by value ..can you give me some examples ?
Aug 21 '08 #5
gits
5,390 Expert Mod 4TB
for example with the assignment-operator (=) you pass a value or in case of javascript's arrays and objects a reference to those objects ... you might have a look here ... for getting an idea of it. it is even good to know when you use AJAX-callbacks where you may closure the reference to an object and easyly load data in the background to a js-business-object/component that you might have implemented.

kind regards
Aug 22 '08 #6
dmjpro
2,476 2GB
yes ... objects and arrays are passed by reference (simple types like boolean, strings, numbers and even functions are passed by value) ... and the reference points to the memory address ... all is 'bound' to the 'base-parent' window (not really but that is your current runtime environment if you like to see it that way), so if you store/pass a reference to something to this window then the garbage collector just knows that you have a reference to it and ignores that reference instead of throwing it ;)

kind regards
If i pass a reference (bound to child window) to parent window and in the mean time i dereference the child window by set null to it then what would happen to that reference as child window reference set to null?
Aug 24 '08 #7
dmjpro
2,476 2GB
it is even good to know when you use AJAX-callbacks where you may closure the reference to an object and easyly load data in the background to a js-business-object/component that you might have implemented.

kind regards
The fundamentals of closure makes a function to be passed as value not by reference? Actually the reference of function passed and the copy of local variables of the called function gets copied with the closure to work the inner function properly. Please explain here.
Aug 24 '08 #8
dmjpro
2,476 2GB
Gits ... Tell me how functions & Strings are passed by Value ..please give me an example.
Aug 24 '08 #9
dmjpro
2,476 2GB
Gits ... Tell me how functions & Strings are passed by Value ..please give me an example.
Recently I tested one thing ....
Expand|Select|Wrap|Line Numbers
  1. var str = "Debasis Jana";
  2. str[0] = 'S';
  3. alert(str[0]); //It still prints D
  4.  
Could you explain ?
Aug 24 '08 #10
dmjpro
2,476 2GB
Recently I went through a Site i found two links ....
The first one i think it's right ...
See these two links ..
[Removed link to competing forum]
Link 2

Please experts have a look ..And throw some comments.
Aug 24 '08 #11
gits
5,390 Expert Mod 4TB
Gits ... Tell me how functions & Strings are passed by Value ..please give me an example.
??? there is enough example in the article link i showed you ... ? what do you exactly want to know? the links you showed in your last post seem to be quite outdated ... currently it is like i already told you ...

kind regards

PS: a better discussion is to be found here
Aug 24 '08 #12
dmjpro
2,476 2GB
Recently I tested one thing ....
Expand|Select|Wrap|Line Numbers
  1. var str = "Debasis Jana";
  2. str[0] = 'S';
  3. alert(str[0]); //It still prints D
  4.  
Could you explain ?
How it works ..please tell me.
Aug 25 '08 #13
gits
5,390 Expert Mod 4TB
with the array-like notation you could just read the character at the specified position - as you could do with charAt() ... have a look here for more information - you cannot set somethig that way. you could use other methods to alter specific characters of a string like replace() or explode the string to a real! array and then rejoin the characters with join() ... etc.

kind regards
Aug 25 '08 #14
dmjpro
2,476 2GB
with the array-like notation you could just read the character at the specified position - as you could do with charAt() ... have a look here for more information - you cannot set somethig that way. you could use other methods to alter specific characters of a string like replace() or explode the string to a real! array and then rejoin the characters with join() ... etc.

kind regards
So String(char array) is immutable :-)
Aug 25 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dean Mitchell | last post by:
Hi, I have a simple STL map container that maps a stl string to a structure as follows. typedef std::map<std::string,TASKLIST> PCLIST; In a class I have a member variable that is defined as...
7
by: netclectic | last post by:
Hi folks, i've searched and searched and can't find any example of what i'm trying to do. Essentially (i think) i need to add a new operator to Number. I'm using eval to evaluate expressions...
2
by: yopwojtek | last post by:
Hello All, i know from some tutorials, that copy constructor and assigment operator is not inherited from base to derived class. i think it make sense but i wrote a little example: class Base {...
1
by: Alexandru Taeaha | last post by:
i am trying to make a program that opens diferent programs from th numpad key. my question is :can i make those keys have more the one assigment like for example standard if i press it opens...
22
by: Luke Matuszewski | last post by:
We all know that feature detection technique works from very beggining of user-agents supporting JavaScript. We can alway check if eg. document has a write property or smth else: ...
3
by: Nathan Sokalski | last post by:
I have a VB.NET function that I am using in an ASP.NET page. The code creates a String, which contains && (the JavaScript Logical AND operator) and is used as part of the JavaScript sent to the...
10
by: Adrian | last post by:
Below is an example of the problem I am having. I don't understand how I can get the compiler to see deriv &operator=(const T &rhs). I am sure this is a common problem - any suggestions? ...
5
by: viscroad | last post by:
I have a confusion when I do some practice, the code and output are as following, print 'In fun()....' In fun().... None <function fun at 0x00CC1270> In fun()....
10
by: Lorenzo Di Gregorio | last post by:
Hello, I've been using Python for some DES simulations because we don't need full C speed and it's so much faster for writing models. During coding I find it handy to assign a variable *unless...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.