Skip to content

Instantly share code, notes, and snippets.

@daytonn
Created February 19, 2015 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daytonn/f19d2b0acd8573961693 to your computer and use it in GitHub Desktop.
Save daytonn/f19d2b0acd8573961693 to your computer and use it in GitHub Desktop.
CWCPOOJS - class method definition
function Person(attributes) {
this.firstName = attributes.firstName;
this.lastName = attributes.lastName;
this.age = attributes.age;
this.address = attributes.address;
}
Person.marry = function(bride, groom) {
bride.spouse = groom;
groom.spouse = bride;
}
Person.prototype.sayHello = function() {
console.log("Hi, my name is " + this.firstName + ". I live in " + this.address.city + ", " + this.address.state + " on " + this.address.street + ".");
};
var bob = Person({
firstName: "Bob",
lastName: "Ject",
age: 33,
address: {
street: "123 Memory Ln",
apt: "0x7fff9575c05f",
zip: "01101",
city: "Browser Town",
state: "Mozilla"
}
);
var ella = Person({
firstName: "Ella",
lastName: "Siff",
age: 1,
address: {
street: "8362 Ram Rd",
apt: "0x7fff8637c02f",
zip: "10101",
city: "Tab City",
state: "Webkitesota"
}
);
Person.marry(ella, bob);
bob.spouse === ella; // true
ella.spouse === bob; // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment