I am trying to understand why JSON.stringify
shows a different output to the object I am expecting to see.
In my case, my object
has a property
of height
and width
So, if I were to do perform the following
const canvas = new fabric.Canvas("c");
console.log("canvas.width: " + canvas.width)
Then the output would be
canvas.width: 300
However, when I perform
console.log(JSON.stringify(canvas));
the output does not include the width.
In my real situation, I am using fabricjs.com
JSFiddle: https://jsfiddle.net/tdge2908/2/
<canvas id="c"></canvas>
<div id="result">
</div>
const canvas = new fabric.Canvas("c");
console.log("canvas.isRendering: " + canvas.width)
const result= document.getElementById("result");
result.innerText = JSON.stringify(canvas);
Likewise, I could add something to my canvas object, and it still won’t show when I stringify it.
EG
const canvas = new fabric.Canvas("c");
canvas.myMadeUpThing = "hello";
console.log("canvas.my made up thing: " + canvas.myMadeUpThing ); //this works
const result= document.getElementById("result");
result.innerText = JSON.stringify(canvas);
JSFiddle: https://jsfiddle.net/tdge2908/4/
Why does calling JSON.stringify
on this object seem to be doing something unexpected?