1

I have problem when running below code. stock50 is quite normal array which contains 50 object with name and number (not empty).

AAA, BBB, CCC, DDD all look fine in console.log, but EEE only shows 9 elements and the last element is undefined. I've tried to change 9 to any number, but the last one always shows undefined. However, it's fine in JsFiddle.

stock50 array is just as below ....

runStockDraw : function(option){
  var pickingStock = stock50,
      tempArray = function(){
        var array =[],
            i = 0;

        while(i<10){
       // AAA  console.log(array[i-1]);
       // BBB  console.log(i);
          array[i] = {};
       // CCC  console.log(array[i]);
          array[i] = $.extend({},stock50[i]);
       // DDD  console.log(array[i]); 
          i++;
        }
       // EEE  console.log(array);
        return array; 
      }();


  var updateData = function(){
    var i = 0,j=0,
        temp = tempArray.shift(),
George
  • 224
  • 3
  • 10
  • If it's fine in JsFiddle, what's your problem? – xdazz Jun 27 '12 at 07:47
  • Self executing functions (which you are using) are usually required to have parens like this `(function() {})()`. See [here](http://stackoverflow.com/questions/9492503/self-executing-function-syntax-and-callback-sytnax-explained) for more of an explanation. – jfriend00 Jun 27 '12 at 07:55
  • 1
    @jfriend00 - That's true, but they are not required in this case, since it's a function expression. It does make it clearer what's going on though. – James Allardice Jun 27 '12 at 08:01
  • I found my problem is caused by 'temp = tempArray.shift()' , if I move it away, the code works fine ... – George Jun 27 '12 at 10:15

0 Answers0