Skip to content

Instantly share code, notes, and snippets.

@daytonn
Last active August 29, 2015 14:15
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/d0b2f2bd3a3fd9521cad to your computer and use it in GitHub Desktop.
Save daytonn/d0b2f2bd3a3fd9521cad to your computer and use it in GitHub Desktop.
CWCPOOJS - correct instance method definition
function Person(attributes) {
this.firstName = attributes.firstName;
this.lastName = attributes.lastName;
this.age = attributes.age;
this.address = attributes.address;
}
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"
}
);
bob.sayHello(); // "Hi, my name is Bob. I live in Browser Town, Mozilla on 123 Memory Ln."
ella.sayHello(); // "Hi, my name is Ella. I live in Tab City, Webkitesota on 8362 Ram Rd."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment