Create js function from string without eval and new Function()

前端 未结 1 1086
清歌不尽
清歌不尽 2021-01-22 05:03

Is there any alternative solution to create js-function from string var, except eval() and Function constructor I\'m not allowed to use this both metho

相关标签:
1条回答
  • 2021-01-22 05:32

    Thanks all of you for interesting answers.

    So, I had read and tried to use all methods, that you suggested me. All of them it’s eval() even you wont be used eval in your code. In my project I fixed problem using WebWorkers. This technologi has a lot benefits, please read article in MDN https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers

    But, I have to use "new Function" for this method.

    So correct answer is:

    You cannot create function from string without eval and new Function().

    The only way it’s to write your own simple parser for that.

    Thanks @brianxautumn

    0 讨论(0)
提交回复
热议问题