How to add methods to a (JSON) object's prototype?

前端 未结 9 1588
故里飘歌
故里飘歌 2020-12-23 14:05

Let\'s say I receive some JSON object from my server, e.g. some data for a Person object:

{firstName: \"Bjarne\", lastName: \"Fisk\"}

Now,

9条回答
  •  时光说笑
    2020-12-23 15:12

    I don't think it is common to transport methods with data, but it seems like a great idea.

    This project allows you to encode the functions along with your data, but it is not considered standard, and requires decoding with the same library of course.

    https://github.com/josipk/json-plus
    

提交回复
热议问题