- 在对象中重写 toJSON 实现 自定义stringify
class Point{
x = 0;
y = 0;
z = 0;
toJSON(){
return [this.x,this.y];
}
}
let point = new Point();
console.log(JSON.stringify(point));
- 结果
2021-07-11 00:53:46
class Point{
x = 0;
y = 0;
z = 0;
toJSON(){
return [this.x,this.y];
}
}
let point = new Point();
console.log(JSON.stringify(point));
下一篇:laravel打印查询sql