SOURCE

var otherFn=()=>{
    return "工具"
}
var origin=function(ab){
    console.log('函数上下文',otherFn)
   var total= ab.price*ab.count
   return this.name+otherFn() +"计算的结果="+ total
}
var j2=origin.toString()
console.log('字符串方法',j2)
var fn =(new Function("return "+""+j2+""))();
console.log('还原后',fn)
// console.log('还原后再执行:',obj({price:3,count:4}))
var adv={
    name:"高级函数",
    run:fn,
    es:()=>{
        return 'this is a function'
    },
    test:function(){
      return  this.run({price:3,count:4})
    }
}
// console.log('还原后再执行:',adv.run({price:3,count:4}))

let objJson= JSON.stringify([adv,adv], ( _key, value) => {
     if(typeof value =='function'){
         return value.toString()
     }
    return value;
  });
  console.log('----************---')
  console.log(objJson)

  let jsonObj=JSON.parse(objJson,(key,value)=>{
       console.log('---',value)
      if (typeof value=='string'){
        if(value.startsWith('function')||value.startsWith('(')){
            return (new Function("return "+""+value+""))()
        }else if(value.includes(')=>')){
            return (new Function("return "+""+value+""))()
        }  
      }
      return value
  })
  console.log('------------------=')
console.log(jsonObj[0].test())
console 命令行工具 X clear

                    
>
console