hypeDocument.functions() is not an Array


(Hans-Gerd Claßen) #1

Hi,

in the documentation hypeDocument.functions() is described to be an array of custom hypefunctions.
Instead it seems to be a object with key = functionname and value = function.

My problem:
I want to iterate thru the object to find a specific key and then run its associated function.
Can’t get it to work without eval-usage. Guess i’m missing something :smile:

Codesnippet:

if(myIndex != -1) 
{
 for (var key in hypeFunctions) {
if(key === myFunctions[myIndex])
{
eval('hypeDocument.functions().' + key + '(hypeDocument, element, event)')//which works as expected, but couldn't be the propper way ...
}
    }
}

(Mark Hunte) #2

I am assuming that myIndex is coming from something else and not manually entered .

Therefore the normal way of calling the function:

hypeDocument.functions().funName(hypeDocument, element, event);

will not work for you because it is dependant on the myIndex int from else where as to which function needs to be called.

But why can you not use:

 hypeDocument.functions()[myIndex];

Instead comparing to a list of function names in myFunctions.


(Hans-Gerd Claßen) #3

well, tried a few combinations, but this doesn’t work either … mainly because hypeDocument.functions() is not an array :slight_smile:


(Mark Hunte) #4

Ah, I see what you mean. I thought I was getting a result but it was an errorless console.log()


(Mark Hunte) #5

How about this.

var  myIndex = 0;
    var hypeFunctions = hypeDocument.functions() ;
    	
    	 var myFunctions = ["func2","func3"];
     

     
     hypeFunctions[myFunctions[myIndex]].apply()

apply()


(Hans-Gerd Claßen) #6

wow, not bad at all!!!
thx for investigating

LG

Hans