Skip to content

Instantly share code, notes, and snippets.

@hackingbeauty
Created October 13, 2014 20:24
Show Gist options
  • Select an option

  • Save hackingbeauty/e34efaf53e7ccec60455 to your computer and use it in GitHub Desktop.

Select an option

Save hackingbeauty/e34efaf53e7ccec60455 to your computer and use it in GitHub Desktop.
Ways of creating objects
// Object literal pattern aka Singleton
var Animal = {
speak: function(words){
console.log(words)
}
}
// Module Pattern
var Animal = (function(){
var internalVar = 1;
var getVar = function(){
return internalVar;
}
return {
getVar: getVar
}
}());
// AMD Module Pattern
define('Animal', function(){
var internalVar = 1;
var AnimalObj = function(){
var getVar = function(){
return internalVar;
}
}
AnimalObj.prototype.getVar = function(){
}
return AnimalObj;
});
var Animal = require('Animal')
//CommonJS method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment