Skip to content Skip to sidebar Skip to footer

Nested Function Repeat

I'm trying to make a function REPEAT, instead of for. Here is my code : function REPETER(nb) { return { INSTRUCTIONS: function(callback) { for(i_repeter=1;i_repeter<

Solution 1:

You need to declare i_repeter within the INSTRUCTIONS function. Because you're not declaring it, you're creating an implicit global. Globals are a Bad Thing, implicit ones doubly so. Since you have a repeater calling a repeater, you end up with crosstalk; the first one thinks it's done before it is.

So:

functionREPETER(nb) {
  return {
    INSTRUCTIONS: function(callback) {
      var i_repeter;                   // <=== Change is herefor (i_repeter = 1; i_repeter <= nb; i_repeter++) callback();
      returnthis;
    }
  };
}

Also don't try to use i_repeter in your function updating xxx (and be sure to declare xxx).

Post a Comment for "Nested Function Repeat"