Assigment operator in JavaScript.  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| |
Have a look at my code snippet .... -
function test(){
-
var obj = new Object();
-
obj.test = "Debasis Jana";
-
alert(obj.test);
-
var obj1 = obj;
-
obj1.test = "DMJPRO";
-
alert(obj.test);
-
}
-
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
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: Assigment operator in JavaScript.
You have been here long enough to know that Java != Javascript.
<Moved>
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Assigment operator in JavaScript. Quote:
Originally Posted by r035198x You have been here long enough to know that Java != Javascript.
<Moved> Sorry here i mistyped.... :-)
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,134
| | | re: Assigment operator in JavaScript.
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
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Assigment operator in JavaScript. Quote:
Originally Posted by gits 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 ?
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,134
| | | re: Assigment operator in JavaScript.
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
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Assigment operator in JavaScript. Quote:
Originally Posted by gits 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?
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Assigment operator in JavaScript. Quote:
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.
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Assigment operator in JavaScript.
Gits ... Tell me how functions & Strings are passed by Value ..please give me an example.
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Assigment operator in JavaScript. Quote:
Originally Posted by dmjpro Gits ... Tell me how functions & Strings are passed by Value ..please give me an example. Recently I tested one thing .... -
var str = "Debasis Jana";
-
str[0] = 'S';
-
alert(str[0]); //It still prints D
-
Could you explain ?
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Assigment operator in JavaScript.
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.
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,134
| | | re: Assigment operator in JavaScript. Quote:
Originally Posted by dmjpro 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 |  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Assigment operator in JavaScript. Quote:
Originally Posted by dmjpro Recently I tested one thing .... -
var str = "Debasis Jana";
-
str[0] = 'S';
-
alert(str[0]); //It still prints D
-
Could you explain ? How it works ..please tell me.
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,134
| | | re: Assigment operator in JavaScript.
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
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Assigment operator in JavaScript. Quote:
Originally Posted by gits 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 :-)
|  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,392 network members.
|