0

How to implement function newObject(without using new operator inside) that would act exactly like new operator? (in javascript)

To be precise I want obj = new MyClass(arg1, arg2) to be the same as obj2 = newObject(MyClass, arg1, arg2)

Any ideas, because I'm out of ideas? :)

siulkilulki
  • 1,054
  • 1
  • 10
  • 18

1 Answers1

0

What you are trying to build is called a factory ,is a common design pattern i would advice you to red through these

http://www.dofactory.com/javascript/factory-method-design-pattern

https://carldanley.com/js-factory-pattern/

so you have a better understanding on what you are about to do

Dayan Moreno Leon
  • 5,357
  • 2
  • 22
  • 24