Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save max-mapper/520c6ccbde89fbdfe72f to your computer and use it in GitHub Desktop.
Save max-mapper/520c6ccbde89fbdfe72f to your computer and use it in GitHub Desktop.
objects vs prototypes
// prototype style (more advanced)
function DB() {}
DB.prototype.open = function() {}
DB.prototype.close = function() {}
DB.prototype.query = function() {}
function connectToDB() {
return new DB()
}
// object style (simpler)
function connectToDB() {
return {
open: function() {},
close: function() {},
query: function() {}
}
}
// with both the external API is the same
var db = connectToDB()
db.open()
db.query()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment