re: 5 Programming Patterns I Like VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Example with no object creation in the function: // Object literal const createContent = function(contentType){ const contentTypes = createCo...
 

I love this solution, very simple;

I usually do this:

const  fromTypes = (types, def = null) => type => (types[type] || def)

const createContent = fromTypes({ post: Post, video: Video }, Unknown)

createContent('post')

code of conduct - report abuse