Are there any uses for function constructors in javascript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Are there any uses for function constructors in javascript?

Constructors like var den = new Function(args, functionBody); are not recommended in javascript according to most resources. what i am wondering , is there time when they become more useful than function declaration and expression? thank you

2nd Jul 2018, 8:00 AM
ADEBAYO DANIEL
ADEBAYO DANIEL - avatar
1 Answer
+ 1
I think when you declare a function you are in a sense constructing it. So I don't see the point of wanting to use the = new Object method. Because even if it worked. It would have the same result as just declaring the function. It makes it simpler to keep the = new Object method for the purpose it was intended for. To say: var Object = function(arguments) however is pretty common practise and I use it in my codes as well.
5th Jul 2018, 11:42 AM
Ryan Els
Ryan Els - avatar