LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 06-06-2005, 01:13 PM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 441

Rep: Reputation: 30
passing variables by reference in javascript


hello,

In javascript, can you pass variables by reference? I only way i know how is to wrap them into an object is there a less hacked way to do this?


thanks,

djgerbavor3
 
Old 06-07-2005, 03:16 AM   #2
xukosky
Member
 
Registered: Apr 2005
Distribution: Becoming Sid
Posts: 142

Rep: Reputation: 15
I know more about java than about javascript (another way of saying I know very few about javascript) but wrapping the variable into an object sounds fine for me.
 
Old 06-07-2005, 11:34 PM   #3
Mohsen
Member
 
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201

Rep: Reputation: 30
Yes, in javascript everything is an object (no primitive there) and paramter passing are done by reference.
Take a look at the following code.
Code:
function s(a) {
  a.setDate(1);
}
d = new Date();
alert(d);
v = d;
s(d)
alert(v);
There is also a nice feature in JavaSctipt. You can make anonymous classes and pass them to a function. In the following exemple an object with 2 properties and a method are passes to setup method.
This code is borrowed from jscalendar 1.0 (The coolest datepicker in the worl).
Code:
  Calendar.setup(
    {
      flat         : "calendar-container", // ID of the parent element
      flatCallback : dateChanged,          // our callback function
      dateStatusFunc : function(date, y, m, d) {
                         if (dateIsSpecial(y, m, d)) return "special";
                         else return false; // other dates are enabled
                         // return true if you want to disable other dates
                       }
    }
  );
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ / Passing a variable by reference to a class member function. sepulture Programming 12 11-15-2005 10:23 PM
Problem passing string::size_type by reference (C++) timhardy Programming 2 04-24-2005 05:14 PM
passing php string to javascript function djgerbavore Programming 2 03-01-2005 11:34 AM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 02:18 PM
Passing variables in PHP???? vous Programming 3 03-20-2003 06:03 AM


All times are GMT -5. The time now is 03:23 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration