Skip to main content
variable names: properties and name.
Source Link
Quentin Pradet
  • 6.9k
  • 1
  • 24
  • 44
  • There's a lot of duplication to get src, name, and so on. Simply use $.map:

      var properties = $.map(["src", "name", "date", "desc"], function(id) {
        return xml.getElementsByTagName(id)[d].childNodes[0].nodeValue;
      }
    

You can then use properties[0]. Not sure how I could return an object with the correct keys as simply as this. Maybe something like

    var properties = {}
    $.each(["src", "name", "date", "desc"], function(i, name) {
      properties[name] = xml.getElementsByTagName(name)[d].childNodes[0].nodeValue;
    }
  • Don't forget any var

  • Create img using this less error-prone technique:

      var img = $('<img>').attr({'alt': properties["name"], name).attr('src',: srcproperties["src"]});
    
  • There's a lot of duplication to get src, name, and so on. Simply use $.map:

      var properties = $.map(["src", "name", "date", "desc"], function(id) {
        return xml.getElementsByTagName(id)[d].childNodes[0].nodeValue;
      }
    
  • Don't forget any var

  • Create img using this less error-prone technique:

      var img = $('<img>').attr('alt', name).attr('src', src);
    
  • There's a lot of duplication to get src, name, and so on. Simply use $.map:

      var properties = $.map(["src", "name", "date", "desc"], function(id) {
        return xml.getElementsByTagName(id)[d].childNodes[0].nodeValue;
      }
    

You can then use properties[0]. Not sure how I could return an object with the correct keys as simply as this. Maybe something like

    var properties = {}
    $.each(["src", "name", "date", "desc"], function(i, name) {
      properties[name] = xml.getElementsByTagName(name)[d].childNodes[0].nodeValue;
    }
  • Don't forget any var

  • Create img using this less error-prone technique:

      var img = $('<img>').attr({'alt': properties["name"], 'src': properties["src"]});
    
Source Link
Quentin Pradet
  • 6.9k
  • 1
  • 24
  • 44

  • There's a lot of duplication to get src, name, and so on. Simply use $.map:

      var properties = $.map(["src", "name", "date", "desc"], function(id) {
        return xml.getElementsByTagName(id)[d].childNodes[0].nodeValue;
      }
    
  • Don't forget any var

  • Create img using this less error-prone technique:

      var img = $('<img>').attr('alt', name).attr('src', src);