Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pass arguments by reference

5 views
Skip to first unread message

David Rettberg

unread,
May 30, 2000, 3:00:00 AM5/30/00
to
How do you pass arguments to a Javascript function by reference?

Thanks,
Dave

Michael Harris

unread,
May 30, 2000, 3:00:00 AM5/30/00
to
You don't --- JScript doesn't support pass by reference...

--
Michael Harris
MVP Scripting


"David Rettberg" <dret...@case-engineering.com> wrote in message
news:#j8$y4ny$GA.250@cppssbbsa03...

Armand

unread,
May 31, 2000, 3:00:00 AM5/31/00
to
Hello,

Try this:

<script>
<!--
function changeArray(theArray) {
theArray[1]=theArray[1]=1;
}
var a=new Array();
a[0]=0;
a[1]=0;
changeArray(a);
alert(a[1]);
// -->
</script>

Regards,
Armand

Armand

unread,
May 31, 2000, 3:00:00 AM5/31/00
to
Here's a reference!

At http://msdn.microsoft.com/scripting/, find this:

Copying, Passing, and Comparing Data
JScript Tutorial

In Microsoft JScript, how data is handled depends on its data type.

By Value vs. By Reference
Numbers and Boolean values (true and false) are copied, passed, and compared
by value. When you copy or pass by value, you allocate a space in computer
memory and put the value of the original into it. If you then change the
original, the copy is not affected (and vice versa), because the two are
separate entities.
Objects, arrays, and functions are copied, passed, and compared by reference
under most circumstances. When you copy or pass by reference, you
essentially create a pointer to the original item, and use the pointer as if
it were a copy. If you then change the original, you change both the
original and the copy (and vice versa). There is really only one entity; the
"copy" is not actually a copy, it's just another reference to the data.


Michael Harris

unread,
May 31, 2000, 3:00:00 AM5/31/00
to
Here's a March 9, 2000 post from Peter Torr on the issue is JScript and pass by value/reference...

======================================================

[...] in COM terms, JScript passes
everything by value - including all the object types (String, Number, Array,
etc.)

The fact that to pass an object by value means to pass its address, and from
its address you can modify an objects properties, is merely an accidental
side effect. You still can't change _the object pointed to by a parameter_
in JScript as you can in VB / C++ / etc.

If you know the difference between a singly-indirect pointer and a
doubly-indirect pointer in C++ then you'll know what I mean.

Peter

--
Peter J. Torr - Microsoft Windows Script Program Manager
pt...@microsoft.com - http://msdn.microsoft.com/scripting/
Please do not e-mail me with questions - post them to this
newsgroup instead. Thankyou!

======================================================


--
Michael Harris
MVP Scripting


"Armand" <ali...@acutronic.com> wrote in message news:u2wj5vvy$GA.197@cppssbbsa04...

Michael Harris

unread,
May 31, 2000, 3:00:00 AM5/31/00
to
JScript to Jscript is still (in at least some sense) COM - JScript is an ActiveX scripting engine.
AFAIK the same limitations on pass by reference still apply for internal function calls.

--
Michael Harris
MVP Scripting


"Armand" <ali...@acutronic.com> wrote in message news:#zLzBYxy$GA.197@cppssbbsa04...
Michael,

That was a response to the question: "How do you pass a string back from
COM in ASP?". So, if that's the question now, .... But, on the other hand,
if it's just jscript-to-jscript, ...

Regards,
Armand

Armand

unread,
May 31, 2000, 3:00:00 AM5/31/00
to
0 new messages