Skip to content

Instantly share code, notes, and snippets.

@pamplonafala
Forked from SegersIan/comparison.js
Created July 26, 2017 14:25
Show Gist options
  • Select an option

  • Save pamplonafala/6bba4d07978edf258d64c61c5408ff33 to your computer and use it in GitHub Desktop.

Select an option

Save pamplonafala/6bba4d07978edf258d64c61c5408ff33 to your computer and use it in GitHub Desktop.
literal objects(literals) vs constructor functions vs factory functions
// Factory function/method
function factoryFunction (){
return {
field : 'value',
method : function() { return 5; }
}
}
const myNewObjectA = factoryFunction();
// Constructor Function
function constructorFunction (){
this.field : 'value',
this.method : function() { return 5; }
}
const myNewObjectB = new constructorFunction();
// Object Literal
const myNewObjectC = {
field : 'value',
method : function() { return 5; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment