Adding a Handler for a Method added in the Constructor

by nfreitas

HTML

<button id=clickMe>Click Me</button>

JavaScript

var Person = function () {
    this.name = "My Name is Person";
    this.sayHello = function () {
        alert(this.name);
    };
    this.sayHelloHandler = this.sayHello.bind(this, this.sayHello);
};

var person = new Person(),
    btn = document.getElementById('clickMe');

btn.addEventListener('click', person.sayHelloHandler, false);