use string to get access to an object
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

use string to get access to an object

From: <andy_w_irvine@hotmail.com>
Date: Wed Feb 01 2006 - 20:14:49 CET

Hi,

Apologies if this has been asked elsewhere, I did search but expect I
didn't hit on the required terminology.

I want to be able to use a string variable called objectName
(original!) to get a reference to an instance of my object
courseObject - created using the following code.

function courseObject(courseName,sectionX,sectionY,layer){
  this.courseName=courseName;
  this.sectionX=sectionX;
  this.sectionY=sectionY;
  this.layer=layer;

  this.updateLocation=updateLocation;
  this.updateLayer=updateLayer;
}

+ simple methods

objectName gets its value from the following section(comes from a drag
and drop API that provides the name of the element that was last
dragged)
objectName= dd.obj.name

There is an object created for each element of the drag & drop
interface. I want to use the string objectName to get a reference to
the object with the name the string contains. To be used in this
fashion.

objectName.updateLocation(section,day)

But as objectName is a string rather than a reference to the object it
will not work. Sure there is a simple solution but I am missing it. Any
help much appreciated.
Received on Tue Feb 7 21:30:22 2006