title: How do I dynamically create event listeners with square bracket notation in node?
body: <p>I'm trying to use a loop for dynamicaly generating event listeners
  in node. But I'm unable to properly target the button objects.
  I've used -global- and -this- but both return an error.</p>
  
  <pre><code>var Gpio = require('onoff').Gpio,
  button1 = new Gpio(17, 'in', 'both'),
  button2 = new Gpio(27, 'in', 'both'),
  button3 = new Gpio(22, 'in', 'both'),
  button4 = new Gpio(23, 'in', 'both');
  
  var i = 5;
  
  while(i--&gt;1)
  {
  console.log(i);
  global["button"+i].watch(function(err, value) {
  if (err) exit();
  x++;
  console.log("button "+i+" has been pressed" );
  })}
  </code></pre>
  
  <p>How can I correctly point to the objects inside the while loop?</p>
  
  <p>Thanks</p>