2

I'm trying to push all function parameters to array, where one parameter is function and i can't do this, because after pushing function to array i have null in this place I have following problem, i have:

var someFunction1 = function(someValue, callback)
{
    // I CAN DO THIS, CALL HERE CALLBACK

    callback();

    // OR PASS CALLBACK TO ANOTHER FUNCTION AND CALL

    // BUT WHEN I'M TRYING THIS:

    var someArray = [];  // OR new Array() ... 
    someArray.push(someValue);
    someArray.push(callback);

    console.log(someArray); // <--- THIS WILL GIVE ME ["EXAMPLE",null] to console
}

var someFunction2 = function()
{
      var callbackFunction = function()
      {
         console.log("SOME TEXT");
      }

      someFunction1("EXAMPLE", callbackFunction);
}

Why i cant push this callback function into array??

Please help :)

I chceck this problem on IOS(PhoneGap Project) now and when i try:

   var array = [];
   array.push(function(){console.log("TEST");});
   console.log(array);

then i get result [null] -> but this work on JSFiddle (also on OSX Safari and IOS Safari) :(

Ri100
  • 89
  • 5
  • 6
    That code works fine http://jsfiddle.net/MQzfM/ – Esailija Jun 20 '12 at 21:05
  • @Ri100: In what conditions the code fails? (browser, version, os, etc.). Seems like the code works in most environments. – jsalonen Jun 20 '12 at 21:07
  • I'm writing app on phoneGap for IOS This is not exactly the same code what i have in app, maybe mistake, i paste tommorow morning code from my app, there this doesnt work. – Ri100 Jun 20 '12 at 21:08

1 Answers1

0

Problem solved:

This is generally some issue on PhoneGap console!

When I'm logging object like:

console.log(function(){ /... CODE .../});

then everything is fine, but after pushing function to array I get 'null' but I check one step further and I try this:

array[0](); //and function was called successfully :)

Its strange and little bit confusing but PhoneGap Console cant log function after push it to Array and log 'null'.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Ri100
  • 89
  • 5