15

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.

4

1 回答 1

33

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

Object.defineProperty(o, 'test', {
    get: function () { return 1; },
    enumerable: true
});
于 2013-03-30T00:46:57.493 回答