Created
March 3, 2019 14:09
-
-
Save BolajiAyodeji/dc6b6f4dbbc0a91815f69104c508d48d to your computer and use it in GitHub Desktop.
Factory Functions vs Construction Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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