Declarativing assigning event handlers with AutoBind

Use a dev console to see the fired events.

To assign a single handler to multiple events:

<button data-events="click, blur" 
    Click me

To assign a seperate handler to every event specified:

<button data-events="click, blur" 
        data-handlers="clickTest, blurTest">
    Click me

Use AutoBind's addEventHandler to add event handlers. Defining an event handler with a traditional function ensures that the this value in the function correctly references the target element (arrow arrow functions don't have their own this. You could also specify any other in-scope function name (that expects an event argument) with addEventHandler.

'use strict';

const ab = new rp.Autobind();

ab.addEventHandler('clickTest', function(e) {
    console.log('event handled');


Click the button or move focus to the input to fire the button's two events.