js eval()函数代替

 function evil(fn) {
        return new Function('return ' + fn)()
  }
 // 执行字符串
      console.log(evil('3+8'))  //11
//执行函数
   evil('function test(){alert(888)};test()')()

你可能感兴趣的:(js eval()函数代替)