Possible Duplicate:
Pass Variables by Reference in Javascript
I desperately look for a solution. I have a javascript project to finish and the only thing that stays in my way is this little thing. I only need something like and ampersand in c to put next to a function parameter so it be passed by reference and it would change outside of the function.
Now I know there are other ways. But in my case this is the only thing that will help me. This is a program that creates binary search trees and I originally made it in c++ but I need to convert it to javascript cause I will show how the tree is generated while the code executes. This is my project. So to create the binary structure only something like an ampersand would help me.
function nod()
{
var info;
var left;
var right;
}
var rad;
rad = new nod();
rad = null;
function create(rad,x) // create(nod *&rad, int x) in c++
{
if(rad==null)
{
rad = new nod();
rad.info = x ;
rad.left = rad.right = null;
}
else
{
if(x < rad.info)
{
create(rad.left,x);
}
else
{
create(rad.right,x);
}
}
}
function read(rad) // read(nod *&rad) in c++
{
var input = [
0,
10,
2,
1,
8,
9,
4,
5,
3,
6,
20,
11,
30,
21,
31,
22,
23,
];
var i;
for(i=1;i<=16;i++)
{
create(rad,input[i]);
}
}
read(rad);