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.

Question/Feature Request: `.props` to work on ES6 class instances

See original GitHub issue

The following does not work because the defined properties are not enumerable:

class Foo {
  get bar() { return somePromise; }
  get baz() { return otherPromise; }
}

Promise.props(new Foo()).then(
  ({bar, baz}) => // doesn't resolve these properties
);

Personally I think it should resolve ES5 non-enumerable properties (such as those defined via ES6 classes). Presently, the code is getting the properties to resolve via Object.keys, which only lists own enumerable properties.

While we’re discussing this, I’d expect .props to resolve inherited properties as well. Is there an intentional reason for only resolving own properties that are enumerable? Or was this just an incidental side effect of using Object.keys for the enumeration?

Do others see value in this behaving one way or the other?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
spioncommented, Oct 6, 2016

We can’t support getter properties without also supporting all non-enumerable properties. Supporting all non-enumerable properties would break backward compatibility. If we ignore that and make a change in 4.0, there will no longer be a way for users to hide properties from the props method. A factory function seems like an adequate replacement, and the classes version will become less ugly once decorators become available.

So overall I’m -1 on this.

1reaction
benjamingrcommented, Oct 5, 2016

I presume the lack of response is that we all only ever used it for enumerable own properties when passing an object literal and not a class.

It was intended to not enumerate enumerable properties since someone might extend Object.prototype with an enumerable property and it’d break .props otherwise.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Private properties in JavaScript ES6 classes - Stack Overflow
The approach here is to use the scope of the constructor function, which is private, to store private data. For methods to have...
Read more >
Classes - JavaScript - MDN Web Docs
Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on...
Read more >
React Class Components with ES6 and Class Fields - G2i
With class fields we no longer need the constructor since the class field will instantiate the property value to the classe's instance. If...
Read more >
ES6 - Classes - Tutorialspoint
Creating Objects. To create an instance of the class, use the new keyword followed by the class name. Following is the syntax for...
Read more >
JavaScript Classes – How They Work with Use Case Example
What are classes in JavaScript? Classes were introduced in EcmaScript 2015 (ES6) to provide a cleaner way to follow object-oriented programming ...
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