Fork me on GitHub

js eval传参

  let fun_str = value; //例:function(a,b){return a.value+b.value}
    try {
      fun_str = fun_str.replace(/[\r\n]/g, "");
      let fun;//this is useful 
      let func = 'fun=' + fun_str;
      let result = eval(func)(a, b);
        return result;
    } catch (err) {
      console.error(fun_str);
      console.log(a, b)
      return true;
    }

用于用户界面配置生成function

posted @ 2018-09-18 14:17  devass  阅读(1701)  评论(0编辑  收藏  举报