View Single Post
  #1  
Old 08-27-2006, 09:46 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Bind a variable to a function?

Ok, after my lack of success in the last thread I'm attempting to build an associative array manually. (Hopefully with more functionaility too, like being able to iterate through it.)

What I want to achieve is standard in OOP, but i'm not sure whether it's possible in GS.

The code will hopefully make more sense:
PHP Code:
function array(indexes,values) {
  
this.inds indexes;
  
this.vals values;
  
this.item item(); 
  return 
this;
}

function 
item(ind) {
   return 
this.vals[this.inds.index(ind)];
}

//then use like:
arr = array({"a","b","c"},{"one","two","three"});
var = 
arr.item("b"); //var should be "two" 
Is this kind of thing possible? I'm trying to achieve some pretty basic OO functionality.

If this is possible it'd really help me with a lot of scripts.

Thanks.
Reply With Quote