How do you give variables reference in javascript?

Posted by Eric on Stack Overflow See other posts from Stack Overflow or by Eric
Published on 2011-01-11T01:31:27Z Indexed on 2011/01/11 1:53 UTC
Read the original article Hit count: 533

Filed under:
|

I want to give variables reference in javascript.

For example, I want to do:

a=1
b=a
a=2

and have b=2, and change accordingly to a.

Is this possible in javascript? If it isn't is there a way to do like a.onchange = function () {b=a}?

What I wanted to do was make a function like makeobject which make an object and puts it in an array and than returns it like

function makeobject() {
   objects[objects.length] = {blah:'whatever',foo:8};
   }

so than I could do

a=makeobject()
b=makeobject()
c=makeobject()

and later in the code do

for (i in objects) {
   objects[i].blah = 'whatev';
}

and also change the values of a,b and c

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about variables