Object creation mechanisms increase the flexibility and reuse of existing code. Here in this post, we will see the Object Creation Pattern in JavaScript. Some patterns to create an object are: Factory pattern Constructor pattern Prototype pattern Constructor / Prototype pattern Factory Pattern The factory pattern uses a function to abstract away the process of creating specific objects and returning their reference. It returns a new instance whenever called. Constructor Pattern In the constructor pattern, instead of returning the instance from the function, we use the new operator along with the function name. { .name = name; .showName = { .log( + .name); } } fruitOne = createFruit( ); fruitTwo = createFruit( ); fruitOne.showName(); fruitTwo.showName(); ( ) function createFruit name this this ( ) function console "I'm " this const new 'Apple' const new 'Orange' // I'm Apple // I'm orage Prototype Pattern The prototype pattern adds the properties of the object to the properties that are available and shared among all instances. { .name = none; } Fruit.prototype.showName = { .log( + .name); } fruitOne = Fruit( ); fruitOne.showName(); fruitTwo = Fruit( ); fruitTwo.showName(); ( ) function Fruit name this ( ) function console "I'm " this const new 'Apple' // I'm Apple const new 'Orange' // I'm Orange Constructor / Prototype pattern This is a combination of the constructor and prototype patterns. The constructor pattern defines object properties, while the prototype pattern defines methods and shared properties. { } Fruit.prototype.name = name; Fruit.prototype.showName = { .log( + .name); } fruit = Fruit(); fruit.name = ; fruit.showName(); ( ) function Fruit ( ) function console "I'm " this const new 'Apple' // I'm Apple 😎Thanks For Reading | Happy Coding😊 Originally at — https://rahulism.tech/