Skip to content

Instantly share code, notes, and snippets.

@snippe
Created November 9, 2014 01:20
Show Gist options
  • Save snippe/9f9200619502dfce525b to your computer and use it in GitHub Desktop.
Save snippe/9f9200619502dfce525b to your computer and use it in GitHub Desktop.
Specifying object
<button id='thebutton'>Click me!</button>
function Person(name) {
this.name = name;
this.sayHello = function () {
alert('Hello ' + this.name);
}
}
function addhandler() {
var p1 = new Person('Jason'),
the_button = document.getElementById('thebutton');
the_button.onclick = p1.sayHello.call(p1);
}
window.onload = addhandler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment