简体   繁体   中英

Does JSON.stringify recognize properties defined with Object.defineProperty?

Does JSON.stringify work with objects that are created like

obj = {}
Object.defineProperty(obj, 'prop', {
  get: function() { return 1 }
  set: function(value) { ... }
})

It returns {} when called on this object.

You might want to set the enumerable option to true, like this:

Object.defineProperty(o, 'test', {
    get: function () { return 1; },
    enumerable: true
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM