Executing functions in a for in loop

Hi,

I’m running a method:


execute: function() {
  for (var i in TXZ.dEvent) {
    if (i != 'initilize' && i != 'execute' && typeof TXZ.dEvent[i] == 'function') {
        TXZ.dEvent[i];
      }
    }
}

I want to execute all functions that evaluate to true but I can’t seem to get the syntax to actually run the function correctly. I know I’m near, but I can’t seem to find any help on this issue online.

Anyone know how? thanks :slight_smile:

  1. function is an object.
  2. function’s name has global scope.
  3. function’s name without parenthesis is a reference to the function’s body.
  4. parenthesis after function’s name is instruction to javascript engine to run function.

hope this helps.

No, it throws a js error “TXZ.dEvent is not a function”. I knew it couldn’t have been so easy, hehe.

EDIT:

This seems to be the correct syntax:

TXZ.dEventi;

I don’t know why this works though if anyone cares to explain. I know that TXZ.dEvent[i] holds the value but when you add “()” it seems to execute the function (in my case). If the value is already a function then in reality what we are doing is “function() { … }()” which doesn’t make much sense.

Can someone shed some light?

To execute a function you invoke it with ()

TXZ.dEvent(i)

Perhaps?

I changed the names around to match it with “this” and I figured it. thank you


this[i]();