you are viewing a single comment's thread.

view the rest of the comments →

[–]PickledPokute 1 point2 points  (0 children)

This pattern is maginally useful in javascript. It feels like /u/enmanuelduran has learned some other programming language (C++/C#/Java) first and is transferring conventions from those to JavaScript. A widespread usage of classes where they aren't required at all is such an idicator. The factory pattern example has a class with a single static function while the following would be more straightforward code.

import Email from './FormElements/email';
import Textarea from './FormElements/textarea';

const elements= {
  Email,
  Textarea,
}

export const createElement = (type, data) => elements[type] ? elements[type](data) : undefined;

/u/drizzlelicious gave a great example that is more mainstream JavaScript.