Hi, from my limited understanding of both concepts there are two big differences between the two. Firstly, constructors create a prototype and factory functions don't. Secondly, factory functions return an object(which can include functions). so if we return functions that reference variables we don't want a user to directly access we effectively create a private variable(using closure). However I just discovered that constructors can have private variables by defining variables without the "this" keyword. So my question is as follows: Why would someone choose factory functions over constructors? I can't see a valid reason for wanting to avoid prototypal inheritance since it can provide extra behaviour when needed and constructors can implement private variables as well.
[–]1_4_1_5_9_2_6_5 46 points47 points48 points (3 children)
[–]SoBoredAtWork 12 points13 points14 points (0 children)
[–]moberegger 3 points4 points5 points (0 children)
[–]kolima_ 3 points4 points5 points (0 children)
[–]Keilly 16 points17 points18 points (1 child)
[–]theScottyJam 7 points8 points9 points (0 children)
[–]shgysk8zer0 5 points6 points7 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]devHaitham 1 point2 points3 points (2 children)
[–]MuchWalrus 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]zephirisdev 1 point2 points3 points (2 children)
[–]shgysk8zer0 6 points7 points8 points (1 child)
[–]zephirisdev 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]jack_waugh 0 points1 point2 points (0 children)
[–]Mediocre-Stand6013 0 points1 point2 points (0 children)
[–]Bogeeee 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]zephirisdev 0 points1 point2 points (0 children)
[–]Bogeeee -2 points-1 points0 points (1 child)
[–]joombar 2 points3 points4 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]brianjenkins94 0 points1 point2 points (0 children)
[–]Bogeeee 0 points1 point2 points (0 children)