Created
February 19, 2015 20:38
-
-
Save daytonn/f19d2b0acd8573961693 to your computer and use it in GitHub Desktop.
CWCPOOJS - class method definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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