Skip to content

Instantly share code, notes, and snippets.

@BolajiAyodeji
Created March 3, 2019 14:09
Show Gist options
  • Save BolajiAyodeji/dc6b6f4dbbc0a91815f69104c508d48d to your computer and use it in GitHub Desktop.
Save BolajiAyodeji/dc6b6f4dbbc0a91815f69104c508d48d to your computer and use it in GitHub Desktop.
Factory Functions vs Construction Functions
// Factory function
// camel naming convention
function createCricle(radius) {
return {
radius,
draw() {
console. log('draw');
}
};
}
const circle1 = createCricle(1)
const circle2 = createCricle(2)
console.log(circle1, circle2);
// Constructor Function
// pascal naming convention
function Circle(radius) {
this.radius = radius;
this.draw = function() {
console.log('draw');
}
}
const circle3 = new Circle(1);
const circle4 = new Circle(2);
console.log(circle3, circle4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment