Skip to content

Instantly share code, notes, and snippets.

@nealfennimore
Created April 22, 2014 16:55
Show Gist options
  • Save nealfennimore/11186574 to your computer and use it in GitHub Desktop.
Save nealfennimore/11186574 to your computer and use it in GitHub Desktop.
Constructor Functions
var jane = {
name: "jane",
status: "cool"
};
function Person(name, status) {
this.name = name;
this.status = status;
this.greeting = function() {
console.log("Hello, I'm " + this.name);
};
}
// Person.prototype.greeting = function() {
// console.log("Hello! " + this.name)
// }
// Person.prototype = {
// greeting: function() {
// console.log("Hello! " + this.name);
// }
// }
var jane = new Person("Jane", "cool");
var mike = new Person("Mike", "cool");
// function Person(name, status) {
// this.name = options.name;
// this.status = options.status;
// }
// var jane = new Person({name: "Jane", status: "cool"});
console.log(jane);
jane.greeting();
mike.greeting();
console.log(jane.greeting === mike.greeting); // False
// If used with prototype will equal true (No instance of same object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment