Virtual function ?

D

David

Hi,

I have an interesting problem. I have created an html based interface that
links to an external .js file with only functions in it. The functions set
an arrays values depending on which function is called by the interface....

The external .js file looks like this below:

function myFunction1(){
arryEntry[0] = "some value1";
arryEntry[1] = "some value2";
arryEntry[2] = "some value3";
arryEntry[3] = "some value4";
}

function myFunction2(){
arryEntry[0] = "other value1";
arryEntry[1] = "other value2";
arryEntry[2] = "other value3";
arryEntry[3] = "other value4";
}
etc...

In the html interface I am calling the function(s) depending on a list
selection. This functions one arg (functionNumber) depends on a list
selection.

function getArryEntries(functionNumber){
eval("myFunction"+parseInt(functionNumber)+"()");
var value0 = arryEntry[0];
var value1 = arryEntry[1];
var value2 = arryEntry[2];
var value3 = arryEntry[3];
}

This all works well so far and the array entries are changed successfully
depending on the getArryEntries(functionNumber) selection.

However, at some time in the session I am adding (actually writing)
additional functions to the external .js file. Appending to the file. The
problem is that the interface will not pick up the newly written functions
on runtime. If the interface is closed and opened again, then it can see the
new functions.

I thought of initiating an array of the existing functions when the
interface loads and append to the array when the new functions are created.
It would then write to the file, but use the array at runtime. No success so
far.

What would be recommended here?

Thanks
David
 
D

David

I found a solution. When loading the interface I am reading the external .js
file and have used RegExps to extract the values from each of the functions
in the external file. For each group of these values I place an entry in a
new Array() ...

var groupVals = new Array();
groupVals [0] = "some value1","some value2","some value3","some
value4";
groupVals [1] = "other value1","other value2","other value3","other
value4";
groupVals [2] = "other value1","other value2","other value3","other
value4";
etc...

New entires that are now added are written to the external file and at the
same time, appending to the groupVals array. I don't have to worry about
accessing the actual external file for the values when new ones are added to
it. Now I have all of the original data plus any new data added, from which
I can use at runtime. The next time the interface launches it will have the
new data written to it and it starts the process all over again.

var groupNeeded = groupVals[0][0];
var groupNeeded = groupVals[0][1];
var groupNeeded = groupVals[0][2];
etc...

Thought I would share my solution.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top