Revision 8cc1beb3-02cb-4413-ba33-0348dee81ac3 - Stack Overflow

> **Possible Duplicate:** 
> [Call a JavaScript function name using a string?](https://stackoverflow.com/questions/496961/call-a-javascript-function-name-using-a-string) 
> [javascript string to variable](https://stackoverflow.com/questions/4639837/javascript-string-to-variable) 

<!-- End of automatically inserted text -->

I have this code:

 

 var Functionify = function() {
 
 return {
 
 init: function(el, t) {
 var els = document.getElementsByClassName(el);
 			var elsL = els.length;
 			
 			while(elsL--){
 				//els[elsL].onclick = els[elsL].getAttribute(t);
 				els[elsL].addEventListener('click', els[elsL].getAttribute(t), false);
 			}
 }
 
 };
 
 }();

Where `el = 'myClassName'` and `t = 'data-id'`

Now, 't' is a string, how can tell the addEventListener function to use 't' (a string) as a function name?

AltStyle によって変換されたページ (->オリジナル) /