I(m trying to use a generic method to parse dom element and attach event Listener to them.

So I add an html5 data attribute to specify the method that should be call when we trigger the event.

What I'm looking for is a way to call the method inside the class by her string value :

```
static addEvent(element, trigger, action)
{
    element.on(trigger, action);
}

```

where element is the dom element where to attach eventListener, trigger is the type of listener and action is the method that we should call inside this class (here I want to call `toggleFullscreen`).

Is there a way to do that?

Edit : need to avoid `eval` solution, and I made a test with this[action] but it's not the excepted result.

Here is my code

dom element :

```
<div class="interface">
    <span class="home_common-fullscreen action fa fa-desktop" data-action="toggleFullscreen" aria-hidden="true"></span>
</div>

```

javascript function :

```
class Interface {
    constructor() {
        this.domElements = jQuery(".interface");

        this.attachAction();
    }

    attachAction()
    {
        let fullScreenButtonElement = this.domElements.find(".action");
        if(fullScreenButtonElement !== undefined)
        {
            if(Array.isArray(fullScreenButtonElement))
            {
                jQuery(fullScreenButtonElement).each(function()
                {
                    Interface.parseAction(this);
                });
            }
            else
            {
                Interface.parseAction(fullScreenButtonElement);
            }
        }
    }

    static parseAction(element)
    {
        let action = element.attr("data-action");
        if(action === undefined)
        {
            throw new InterfaceError("Trying to parse action element without defined data-action attribut");
        }

        let trigger = typeof element.attr("data-trigger") !== 'undefined' ? element.attr("data-trigger") : "click";

        try
        {
            Interface.addEvent(element, trigger, action);
        }
        catch(err)
        {
            console.log(action + "not found in Interface")
        }
    }

    static addEvent(element, trigger, action)
    {
        element.on(trigger, action);
    }

    toggleFullscreen()
    {
        alert("foo");
    }
}

```

[JSFiddle](https://jsfiddle.net/lerzats/ah8cr1ca/)