Question/Feature Request: `.props` to work on ES6 class instances
See original GitHub issueThe 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:
- Created 7 years ago
- Comments:6
Top 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 >
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 Free
Top 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
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.
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.