The following JavaScript code does something I didn't expect.
let foo = {};
Reflect.defineProperty(foo,'bar',{value:1});
console.log(foo); // { bar: 1 }
console.log(JSON.stringify(foo)); // { }
Why is the serialized output from JSON.stringify missing the new bar property?
Aucun commentaire:
Enregistrer un commentaire