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>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
  
  <button class="button">Tom</button>
<button class="button2">Ireland</button>
</body>
</html>
 
function Person(name){
        this.name = name;
        this.alert = function(){
            alert("hello " + this.name);
        };
}
function area (location, name){
        this.name = name;
        this.location = location;
        this.alert = function(){
            alert("hello " + this.name + " you live in " + this.location);
        };
}
$(document).ready(function(){
    $(".button").click(function(){
        var clicked = $(this).text();
        window.Person = new Person(clicked);
        Person.alert();  
    });
    $(".button2").click(function(){
        var location = $(this).text();
        var name =  window.Person.name;
        window.area = new area(location, name);
        area.alert();  
    });
});
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers