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

猜你喜欢

转载自www.cnblogs.com/nanguabushuohua/p/9668636.html