Problem with accessor descriptors
See original GitHub issueI’m running into some strange behavior with Object.defineProperty
used with an accessor descriptor in that when it is subsequently checked with Object.getOwnPropertyDescriptor
, the get
function originally supplied is no longer available (and value
is there in its place).
var jsdom = require("jsdom");
var window = jsdom.jsdom().defaultView;
Object.defineProperty(window, 'testVar', {enumerable: true, get: function () {
return 'test';
}});
console.log('get' in Object.getOwnPropertyDescriptor(window, 'testVar')); // unexpectedly `false`
Available for testing on https://runkit.com/5864b94c65714b0014bfd65a/588fe1aee1800c0014f30c5d
And to confirm the fact that using the property nevertheless works fine in the same Node environment with global
or an arbitrary object, see https://runkit.com/5864b94c65714b0014bfd65a/588fe2d39af44e00146a5322
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
why data descriptors and accessor descriptors can not be ...
Object.defineProperty creates immutable properties. That's why you can't change them by other descriptors. However You can configure ...
Read more >Object.defineProperty() - JavaScript - MDN Web Docs
A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property...
Read more >Enhancing JavaScript Objects with Descriptors and Symbols
There is a lot of freedom in implementing out own custom property descriptors (especially accessors), and the things you could do with them...
Read more >Property getters and setters - The Modern JavaScript Tutorial
fullName = "Test"; // Error (property has only a getter) ... Descriptors for accessor properties are different from those for data ...
Read more >Object defineProperties() in JavaScript - Scaler
Try quiz, solve problems & win rewards! Go to Challenge ... The accessor descriptor takes the get and sets the value.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That is probably (but not definitely) https://github.com/nodejs/node/issues/6287, which looks like it might be fixed in the next Node.js release…
Oh, sorry, I got turned around, this is https://github.com/nodejs/node/issues/2734 which is still open…