eval解析的函数传参 object array

1 const fn = (...args) => {
2     console.log(...args)
3 }
4 
5 const handleEval = (fnName,...args) => eval(`${fnName}(${args.map(item => JSON.stringify(item)).join(',')})`)
6 
7 handleEval('fn',[1,2,3],{name:'zhangsan',age:18},4,5,'string') // [ 1, 2, 3 ] { name: 'zhangsan', age: 18 } 4 5 'string'

 

posted @ 2021-12-17 10:37  谁凭花解语  阅读(98)  评论(0编辑  收藏  举报