question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with accessor descriptors

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
domeniccommented, Feb 14, 2017

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…

0reactions
domeniccommented, Apr 24, 2017

Oh, sorry, I got turned around, this is https://github.com/nodejs/node/issues/2734 which is still open…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found