The thing to remember is that you can mutate an object passed in, but you
can't change it to a new object.

If you need a function that changes a variable, then instead of doing:

function change(obj) {
    obj = [];
}

var a = {};
change(a); //won't work

You could do:

function change(obj) {
    newObj = [];
    return newObj;
}

var a = {};
a = change(a); //this works, because you're assigning the new value

So, if you want to assign something new to a, you have to do it via an
assignment, not via a function call. Hope that makes sense - it's been a
long day...

On 13 December 2010 23:05, Rajat Mittal <[email protected]> wrote:

> Yeah, its mostly out of curiosity.
>
> I do not intend to do anything like this as of now. I was just trying to
> figure out how to do it. The global object solution looks ok and I thought
> about it but I was wondering if there is something cleaner.
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]<jsmentors%[email protected]>
>



-- 
Nick Morgan
http://skilldrick.co.uk
@skilldrick <http://twitter.com/skilldrick>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to