Skip to content

Instantly share code, notes, and snippets.

@morsdyce
Created August 6, 2014 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morsdyce/2cb881ff3034afda8555 to your computer and use it in GitHub Desktop.
Save morsdyce/2cb881ff3034afda8555 to your computer and use it in GitHub Desktop.
why people hate javascript #js
function profiles(callback) {
var profileList = [];
gapi.client.analytics.management.webproperties.list({
accountId: '~all'
}).execute(function (webProperties) {
for (var i = 0, limit = webProperties.items.length; i < limit; i++) {
var webProperty = webProperties.items[i];
var webPropertyItem = {
id: webProperty.id,
name: webProperty.name,
profiles: []
};
(function (webProperty, webPropertyItem) { // closure
gapi.client.analytics.management.profiles.list({
accountId: webProperty.accountId,
webPropertyId: webProperty.id
}).execute(function (profiles) {
(function (profiles, webPropertyItem) { // closure
for (var j = 0, jLimit = profiles.items.length; j < jLimit; j++) {
var profile = profiles.items[j];
webPropertyItem.profiles.push({
name: profile.name,
id: profile.id,
webPropertyId: profile.webPropertyId
});
}
}(profiles, webPropertyItem));
});
}(webProperty, webPropertyItem));
profileList.push(webPropertyItem);
}
if (callback) {
callback(profileList);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment