Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<button id="button">Alert Name</button>
</body>
</html>
 
var Person = function(name) {
  this.name = name;
  // lets assign this to that :)
  var that = this;
  this.sayHi = function() {
    // That is used to call the foo property
    alert(that.name);
  };
};
var ahmad = new Person('Ahmad');
var element = document.getElementById('button');
element.addEventListener('click', ahmad.sayHi); // => Ahmad
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
ahmadajmipro
0viewers