Skip to content

Instantly share code, notes, and snippets.

@ricca509
Created November 5, 2012 22:10
Show Gist options
  • Save ricca509/4020717 to your computer and use it in GitHub Desktop.
Save ricca509/4020717 to your computer and use it in GitHub Desktop.
Constructor invocation
var Book = function(title) {
this.title = title;
}
// Let's add a method to Book
Book.prototype.getTitle = function() {
return this.title;
}
// Create an instance of Book
var myBook = new Book('A noontide blazing');
console.log(myBook.getTitle());
// output: "A noontide blazing"
// Now add a new property to Book
Book.prototype.pages = 200;
// My object inherits the new property even after the instantiation
console.log(myBook.pages);
// output: 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment