0

http://jsfiddle.net/JonnyD/H2Dpe/3/

Console log:

   [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
     (index):104

   function (newFeedItems) {
       console.log(feedItems);
   } (index):113

   Uncaught TypeError: Object function (newFeedItems) {
      console.log(feedItems);
   } has no method 'sort' 

Where is it getting this from?

function (newFeedItems) {
    console.log(feedItems);
} (index):113

when it's supposed to be:

[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]

Take a look at the functions fetchFeeds() and processLatestFeed(). The problem starts at processLatestFeed(function(newFeedItems) {

function fetchFeeds() {
    fetchVideos(function(newVideoItems) {
        fetchPodcasts(function(newPodcastItems) {
            var newFeedItems = newVideoItems.concat(newPodcastItems);
            console.log(newFeedItems);
            processLatestFeed(function(newFeedItems) {
                console.log(feedItems);
            });
        });
    });
}

function processLatestFeed(newFeedItems, callback) {
    console.log(newFeedItems);
    newFeedItems.sort(function(a,b) {return (a.date > b.date) ? -1 : ((b.date > a.date) ? 1 : 0);});

    for (i in newFeedItems) {
        var newItem = newFeedItems[i];

        if (!isItemInFeed(newItem)) {
            feedItems.push(newItem);
        }

        if (feedItems.length == 50) {
            break;   
        }
    }

    callback();
}
3
  • 1
    Can you describe your questions further please? I don't think I understand properly what you're trying to say Commented Feb 23, 2014 at 3:03
  • @ZachSaucier see newFeedItems and how it is logged to the console, you can see how it correctly displays that it's an array of objects [Object, Object, Object....] however when newFeedItems get passed into processLatestFeed(function(newFeedItems)... it doesn't seem to pass in as an array of object but as source code itself (see the second part of the console log). Commented Feb 23, 2014 at 3:06
  • 1
    Not sure If I understood, but change this: processLatestFeed(newFeedItems, function(){ console.log(feedItems); }); Commented Feb 23, 2014 at 3:11

1 Answer 1

1

You are passing a function as first argument to processLatestFeed:

processLatestFeed(function(newFeedItems) {
  console.log(feedItems);
});

but you defined that function to accept an array as first argument and the callback as second argument:

function processLatestFeed(newFeedItems, callback) {
    console.log(newFeedItems); // <- this logs the function source
    // ...
}

So you have to call the function as

processLatestFeed(newFeedItems, function() {
  // you are not passing an arguments to the callback
});
Sign up to request clarification or add additional context in comments.

2 Comments

im an idiot! been playing around with JavaScript all day - think this my cue to take a break :)
Yep, that often helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.