Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Does JavaScript have input _and_ output parameter support?

Posted on 2006-10-26
6
Medium Priority
?
462 Views
Last Modified: 2008-02-01
Hi.

<?php
function aa(a,b,c)
      {
      c = a + b;
      return a - b;
      }

var j = 0;
alert(aa(1,2,j));
alert(j);
?>

What happens at the moment is I have an alert of -1 and then 0.

How do I update j?

I can't use j in the function as that restricts it to a single variable.

In PHP I would ...

<?php
function aa($a, $b, &$c)
 {
 $c = $a + $b;
 return $a - $b;
 }
$j = 0;
$x = 0;
$k = aa(1, 2, $j);
$l = aa(3, 5, $x);
?>

sort of thing.

Similar facilities exist in VB and Delphi. Just can't seem to work out the JavaScript way.

Ta!
0
Comment
Question by:Richard Quadling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 17810885
 Javascript parameters are pass by value.  So, you would need to have the function return a result
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17810903
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<title> function parms </title>
</head>
<body>
<script type='text/javascript'>
  function inc( x ) {
    x++;
  }
  var i = 0;
  document.write( 'Before: ' + i );
  inc( i );
  document.write( ' After: ' + i );
</script>
</body>
</html>
----------------------------------
Output is:
----------------------------------
Before: 0 After: 0
0
 
LVL 40

Author Comment

by:Richard Quadling
ID: 17811137
Not quite.

I need to modify a value which is passed as well as generate a result.

I'm using a class_param to do this now. I was hoping for a byref mechanism.

0
 
LVL 40

Author Comment

by:Richard Quadling
ID: 17811408
function class_Param(m_InitValue)
      {
      this.value = m_InitValue;
      }


i_magic_value = new class_Param(0);

can then use

x(i_magic_value);

and x can write to i_magic_value.value

Sorted!
0
 
LVL 1

Accepted Solution

by:
kodiakbear earned 0 total points
ID: 17886466
Closed, 50 points refunded.
kb
Experts Exchange Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question