-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reflect.enumerate() appears deprecated #19
Comments
Update: Unfortunately
Alternatively, if your objects are being created by a custom class, you could create a custom iterator method:
...but in many cases it would be preferable to just use a |
Will Trying your class example, it seems like using a for-in within the class does not provide a new instance of that class any access to its parents' keys. class Entity {
*[Symbol.iterator]() {
for (let key in this) {
yield key;
}
}
}
var e = new Entity();
e.foo = 'do';
console.log(Array.from( e[Symbol.iterator]() ))
/*
Array [
"foo"
]
*/
var f = Object.create(new Entity)
f.fee = 'fo'
console.log(Array.from( f[Symbol.iterator]() ))
/*
Array [
"fee"
// no 'foo'
]
*/ |
The bottom right region of this handy chart will not sate our thirst for answers, but will answer this conundrum. |
"Not without extra code" |
Ah, you're right about But the
|
I should add that I don't have much confidence that the above approach would be very useful in practice. The reason I tried this approach was this quote from an article on metaprogramming in ES6:
A
The main difference when using an iterator is that you could loop over all enumerable properties using The good news is that most enumerable properties are instance properties rather than properties that need to be defined on the prototype, so
|
I was able to use this with Babel, but MDN says it'll get deleted any time.
Good alternative for "Names of all enumerable properties as an array"?
The text was updated successfully, but these errors were encountered: