LoginSignup
6
5

More than 5 years have passed since last update.

JSON.stringifyとtoJSON

Posted at

JSON.stringifyを呼び出した時、そのオブジェクトにtoJSONメソッドがあればそれをフックするそうです。
https://developer.mozilla.org/en/JSON#toJSON()_method

JSON.stringify.js
var obj = {
  toJSON: function() {
    console.log("toJSON called");
  }
};
JSON.stringify(obj); // output "toJSON called"

フックすると通常のJSON.stringifyの出力は当然ながら出力されません。
これはMDNで知ったのですが、ECMAScriptで標準化された仕様なのでしょうか?

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5