0

I am toying around with making a custom Javascript class system and am currently interested in making my object instances be well identified in the console / devtools, as described in this previous question of mine. So far, I am getting the impression that the only way to achieve what I want is to to use eval to create named functions, as described in this other question.

Are there any tradeoffs I should expect if I use eval to create my classes? I am not worried about eval itself being slow1 or about security2 but I heard that using eval could possible disable JIT compilation for the rest of the code. Is this true? If it is, what code would be affected? Just the function with eval? The function and all its parent functions? The whole module? What steps could I take to make sure the eval affects my code as little as possible?


1 I would only need to use eval to do some metaprogramming at the start of the script. It wouldnt run inside a performance critical loop.

2 I would never call eval with user input and in my case I could even use a regex to check if the input string is a valid identifier / function name.

Community
  • 1
  • 1
hugomg
  • 68,213
  • 24
  • 160
  • 246
  • Why do you require a named function? If not in strict mode, `function getFunctionRef() { return getFunctionRef.caller; }` – Paul S. Aug 05 '14 at 15:33
  • The original reasoning was that the function names would show up in error messages and in the console. I ended up managing to solve my original problem without needing eval but now I wonder what would be the consequences if I did use eval. – hugomg Aug 05 '14 at 15:36

0 Answers0