// Object literalconstcreateContent=function(contentType){constcontentTypes=createContent.contentTypes;constcreateType=contentTypes[contentType]||contentTypes.default;returncreateType();// or new createType() if its a class constructor}createContent.contentTypes={post:Post,video:Video,default:Unknown};
Example with no object creation in the function:
I love this solution, very simple;
I usually do this:
This is how redux architecture works ;)