对函数字符串化
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JSON.stringify 会删除对象中的任何函数</h1>
- <p id="demo"></p>
- <script>
- var obj = { name: "Bill Gates", age: function () {return 62;}, city: "Seattle" };
- var myJSON = JSON.stringify(obj);
- document.getElementById("demo").innerHTML = myJSON;
- </script>
- </body>
- </html>