I'm working through some Windows 8 tutorials from the msdn website. Specifically I'm on this one.
Part of my code (copied from the tutorial is blowing my mind why it's erroring. Sample below:
(function () {
"use strict";
var list = getBlogPosts();
var groupedItems = list.createGrouped(
function groupKeySelector(item) { return item.group.key; },
function groupDataSelector(item) { return item.group; }
);
var dataPromises = [];
var blogs;
var blogPosts = new WinJS.Binding.List();
function getFeeds() {
blogs = [
{
key: "blog1",
url: 'http://windowsteamblog.com/windows/b/developers/atom.aspx',
title: 'tbd', updated: 'tbd',
acquireSyndication: acquireSyndication, dataPromise: null
},
// lots more entries ...
];
blogs.forEach(function (feed) {
feed.dataPromise = feed.acquireSyndication(feed.url);
dataPromises.push(feed.dataPromise);
});
return WinJS.Promise.join(dataPromises).then(function () { return blogs });
}
// more code...
})();
At the line dataPromises.push(feed.dataPromise);
I get the error JavaScript runtime error: Unable to get property 'push' of undefined or null reference
. You can see dataPromises
is defined and initialised to an empty array near the top of the file (I've also tried initialising it with new Array();
).
What am I doing wrong here??? I'm guessing I've made some stupid screw up... Incidentally, the 3 places dataPromises
appears in the snippet above are the only places it appears anywhere in the project.
My first thought was hoisting but unless something magical is going on, I'm not explicitly declaring dataPromises
in any local scopes that might be overriding the top function scope.