title: How to sequence commands in callback hell
body: <p>The code below takes a screenshot and cuts off a certain element passed as a CSS selector.</p>
  <pre><code>const imageLib = require('imagelib/imageLib');
  
  withoutElementScreenshot.prototype.command = function (selector, filename, cb) {
      var self = this;
  
      function execute(client, selector, filename, cb) {
          client.element('css selector', selector, function (element) {
              client.elementIdLocationInView(element.value.ELEMENT, function (location) {
                  client.elementIdSize(element.value.ELEMENT, function (size) {
                      client.takeScreenshot(filename, function () {
                          imageLib(filename).pngToData(function () {
                              for (var x = location.value.x; x &lt; size.value.width + location.value.x; x++) {
                                  for (var y = location.value.y; y &lt; size.value.height + location.value.y; y++) {
                                      this.setPixel(x, y, 255, 255, 255, 255);
                                  }
                              }
                              this.toPng(filename, function () {
                                  client.log('Screenshot without element would be saved into ' + filename);
                                  cb();
                              });
                          });
                      });
                  });
              });
          });
      }
  </code></pre>
  <p>How do I pass an array of selectors to cut them all off? I cannot iterate through the array since the takeScreenshot function is in between callbacks.</p>