+ 4

How to use Function constructor ? [Solved]

In the following code , the first compile one works as expected but second doesn't , why so? ---------------------------- var compile=new Function("data",'return ""+data.abc') console.log(compile(abc)); compile=new Function("data",'return re()'); console.log(compile(abc)) ---------------------- re function returns same string as we have in first compile , i. e. ""+data.abc . So my question is ,does re function returns ""+data.abc or """+data.abc", if it's the former one than it should work well but if it's the latter than it doesn't and so what should i do ? Ty! Here is the code, https://code.sololearn.com/W9UNfxEKENqa/?ref=app Edit: ok , it works fine for just {{abc}}, after adding the string returned by re to return but then again it fails for something like {{abc}} world.

2nd Mar 2021, 7:24 PM
Abhay
Abhay - avatar
4 ответов
+ 4
Ty everyone for your time! I was playing with first compile sentence to see how should i structure it to output "hello world hello" And so this is what i did , var compile=new Function("data",'return ""+data.abc + " world " + data.abc') well this gave me an idea to add double quotes around the actual strings like "world" And so i fixed fnStr+=`+${t}` as fnStr+=`+"${t}"`.
3rd Mar 2021, 9:44 AM
Abhay
Abhay - avatar
+ 3
BUZZSAW it's ok , but then you don't need to comment as well , those who know will answer me but i appreciate your willingness to help me!
2nd Mar 2021, 7:32 PM
Abhay
Abhay - avatar
+ 2
I just took a fast look 😅 I wasn’t concentrate
2nd Mar 2021, 9:24 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
0
Im sorry I cant help I havent done java
2nd Mar 2021, 7:28 PM
BUZZSAW
BUZZSAW - avatar