constructor vs factory function javascript