title: How to pass a parameter to a function in casperjs?
body: <p>I have stored all the images url in an array, and am trying to test whether image has loaded properly. If you see the below code, i had to repeat few set of lines again and again. How can i write it to be generic?</p>
  
  <pre><code>casper.start()
  var imagesArray = [];
  imagesArray = ['https://www.google.co.in/images/srpr/logo11w.png',
  'https://www.google.co.in/images/srpr/logo1w.png']; 
  
  casper.thenOpen(imagesArray[0], function () {
      if (this.currentHTTPStatus === 404) {
          this.warn(imagesArray[0] + ' is missing (HTTP 404)');
      } else if (this.currentHTTPStatus === 500) {
          this.warn(imagesArray[0] + ' is broken (HTTP 500)');
      } else {
      this.echo(' is okay (HTTP %s)');
      }
  });
  
  casper.thenOpen(imagesArray[1], function () {
      if (this.currentHTTPStatus === 404) {
          this.warn(imagesArray[0] + ' is missing (HTTP 404)');
      } else if (this.currentHTTPStatus === 500) {
          this.warn(imagesArray[0] + ' is broken (HTTP 500)');
      } else {
      this.echo(' is okay (HTTP %s)');
      }
  });
  
  
  casper.run(function() {
  this.echo('Image loading test finished');
  this.exit();
  }); 
  </code></pre>
  
  <p>I tried the below method, calling a function but its throwing parser error, what am i doing wrong, or how can i proceed with it?</p>
  
  <pre><code>function checkImages(item){
  if (this.currentHTTPStatus === 404) {
  this.warn(item + ' is missing (HTTP 404)');
  } else if (this.currentHTTPStatus === 500) {
  this.warn(item + ' is broken (HTTP 500)');
  } else {
  this.echo(' is okay (HTTP %s)');
  }
  }
  
        casper.thenOpen(imagesArray[0], function () {
      this.evaluate(checkImages(imagesArray[0]));
      });
  
        casper.thenOpen(imagesArray[1], function () {
      this.evaluate(checkImages(imagesArray[1]));
      });
  </code></pre>
  
  <p>Thanks in advance.</p>