Is there any possibility to have JSON.stringify preserve functions?

前端 未结 9 1886
一个人的身影
一个人的身影 2020-12-01 05:14

Take this object:

x = {
 \"key1\": \"xxx\",
 \"key2\": function(){return this.key1}
}

If I do this:

y = JSON.parse( JSON.st         


        
9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 06:18

    To my knowledge, there are no serialization libraries that persist functions - in any language. Serialization is what one does to preserve data. Compilation is what one does to preserve functions.

提交回复
热议问题