click buttons

http://segmentfault.com/q/1010000004074509

by Justin Chen

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<button>one</button>
<button>two</button>
<button>three</button>
<button>four</button>
<button>five</button>

JavaScript

var bindEvents = function(buttons, array){
    [].forEach.call(buttons, function(item, i){
    	item.addEventListener('click', function(){
        	console.log(array[i]);
        }, false);
    });
};

var arr = ['one', 'two', 'three', 'four', 'five'],
    btns = document.getElementsByTagName('button');

bindEvents(btns, arr);