JS | TS 自定义 object 的 json 序列化

时间:2021-08-24 16:59:46   收藏:0   阅读:12
class Point{
  x = 0;
  y = 0;
  z = 0;

  toJSON(){
    return [this.x,this.y];
  }
}

let point = new Point();
console.log(JSON.stringify(point));

技术分享图片

原文:https://www.cnblogs.com/chilli-with-fish/p/15180716.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!