Object.defineProperty with { get: undefined, set: undefined }

Jeff Walden jwalden+es at MIT.EDU
Mon Aug 3 16:35:26 PDT 2009


  Object.defineProperty(obj, propname, { get: undefined, set: undefined });

Assuming obj has no property named by propname (whether it does or not is basically irrelevant to this question), the given expression apparently defines a property with this property descriptor:

     [[Get]]: undefined,
     [[Set]]: undefined,
     [[Enumerable]]: false,
     [[Configurable]]: false

The effect of getting such a property is to return undefined; setting it either has no effect or throws, depending on the precise code construct being used.

Anyway: what exactly is the meaning of a descriptor whose [[Get]] and [[Set]] fields are both |undefined|?  Merely [[Set]] being |undefined| has a sensible meaning (readonly yet not necessarily constant property).  Merely [[Get]] being |undefined| makes less sense -- one-way communication with an object via property setting, rather than by a method call? -- but okay, I can accept it as plausibly useful.  But both [[Get]] and [[Set]] being undefined?  I don't see the purpose or rationale behind it.  Could someone enlighten me?


More information about the es-discuss mailing list