Could you compare usage of Module Pattern vs Constructor/Prototype pattern?

Technology CommunityCategory: JavaScriptCould you compare usage of Module Pattern vs Constructor/Prototype pattern?
VietMX Staff asked 3 years ago

The module pattern is typically used for namespacing, where you’ll have a single instance acting as a store to group related functions and objects. This is a different use case from what prototyping is good for. They’re not really competing with each other; you can quite happily use both together (eg put a constructor-function inside a module and say new MyNamespace.MyModule.MyClass(arguments)).

Constructor-functions and prototypes are one of the reasonable ways to implement classes and instances. They don’t quite correspond to that model so you typically need to choose a particular scheme or helper method to implement classes in terms of prototypes.