对函数字符串化

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JSON.stringify 会删除对象中的任何函数</h1>
  6.  
  7. <p id="demo"></p>
  8.  
  9. <script>
  10. var obj = { name: "Bill Gates", age: function () {return 62;}, city: "Seattle" };
  11. var myJSON = JSON.stringify(obj);
  12. document.getElementById("demo").innerHTML = myJSON;
  13. </script>
  14.  
  15. </body>
  16. </html>