I try to do this:
posts[fbposts[fbpost].id] = ({
name: fbposts[fbpost].from.name,
link: "http://www.facebook.com/" + fbposts[fbpost].from.id,
img: "http://graph.facebook.com/" + fbposts[fbpost].from.id + "/picture",
message: fbposts[fbpost].message,
to: ({
name: name,
link: link,
}),
created: timeDifference(Date.parse((fbposts[fbpost].updated_time))),
sortvar: (Date.parse(fbposts[fbpost].updated_time)),
comments: ({
/* looping through the comments*/
if (fbposts[fbpost].comments.count) {
for (var comment in fbposts[fbpost].comments.data) {
name: fbposts[fbpost].comments.data[comment].from.name;
link: "http://www.facebook.com/" + fbposts[fbpost].comments.data[comment].from.id;
img: "http://www.facebook.com/" + fbposts[fbpost].comments.data[comment].from.id; + "/picture";
message: fbposts[fbpost].comments.data[comment].message;
created: timeDifference(Date.parse(fbposts[fbpost].comments.data[comment].created_time));
}
}
})
});
}
But obviously when I get to the comment, the script brakes, as I can’t run loops within and conditionals within the declaration of the object. How should I go about doing this instead?
Actually, you could do this using a closure…
What this will do is define an inline (single use) function and call it immediately, returning valid javascript as a result.
x is now an object which looks like: