Skip to content

Instantly share code, notes, and snippets.

@conspirator
Created October 8, 2010 04:57
Show Gist options
  • Save conspirator/616383 to your computer and use it in GitHub Desktop.
Save conspirator/616383 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>OOJS Test Page</title>
<script type="text/javascript">
var Person = function(x){
this.firstName = x && x.firstName ? x.firstName : "Barack";
this.lastName = x && x.lastName ? x.lastName : "Obama";
this.job = x && x.job ? x.job : "President";
}
Person.prototype.writePerson = function(x){
var y = document.getElementsByTagName('h1')[x];
y.innerHTML = this.getPerson();
}
Person.prototype.setFirstName = function(x){
this.firstName = x;
}
Person.prototype.setLastName = function(x){
this.lastName = x;
}
Person.prototype.setJob = function(x){
this.job = x;
}
Person.prototype.setPerson = function(x){
this.firstName = x.firstName;
this.lastName = x.lastName;
this.job = x.job;
}
Person.prototype.getPerson = function(){
return this.firstName + " " + this.lastName + " - " + this.job;
}
function init() {
var me = new Person();
me.setFirstName('Christopher');
me.setLastName('Webb');
me.setJob('Developer');
me.writePerson(1);
var president = new Person();
president.writePerson(0);
var pooh = me;
pooh.setLastName('Robbin');
pooh.setJob('Advisor');
pooh.writePerson(2);
var wife = new Person();
wife.setPerson({
firstName: "Joan",
lastName: "Leach",
job: "Teacher"
});
wife.writePerson(3);
var friend = new Person({
firstName: "Chris",
lastName: "Powers",
job: "Uber Developer"
});
friend.writePerson(4);
}
</script>
</head>
<body onload="init()">
<h1>One</h1>
<h1>Two</h1>
<h1>Three</h1>
<h1>Four</h1>
<h1>Five</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment