There's a paragraph related to the in operator that goes like this :
There's (currently) no built-in way to get a list of all properties which is equivalent to what the in operator test would consult (traversing all properties on the entire [[Prototype]] chain, as explained in Chapter 5). You could approximate such a utility by recursively traversing the [[Prototype]] chain of an object, and for each level, capturing the list from Object.keys(..) -- only enumerable properties.
Why do we need to capture only the enumerable properties. The in operator also checks for non-enumerable properties as well. So instead of using Object.keys(), shouldn't we use Object.getOwnPropertyNames() to build the utility?
The in operator also checks for non-enumerable properties as well
No I don't think it does. See:

Actually, sorry... I see what you mean, the in operator, not the for..in loop.
I think what I was thinking, but conflated ideas and didn't articulate well in that paragraph, is that there's no built-in way to get all the properties from the whole prototype chain (which is what both forms of in do). There's actually two different kinds of lists you might want to get: any existing property (the in test) or any enumerable property (the for..in loop).
If you wanted to get the any-property list (emulating the in operator), you're right, you'd want to use the getOwnPropertyNames(..). If you wanted to get the enumerable-property list (emulating the for..in loop), you'd want to use Object.keys(..).
I should definitely clarify this paragraph in the second edition.
But that's when you are using the in operator inside a for..in loop. However, when used alone, it checks for non-enumerable properties as well. The code below prints true :
var o = {a: 1};
Object.defineProperty(o, "b", {value: 2, enumerable: false});
var x = Object.create(o);
"b" in x;
Yes. Exactly what I meant to say :+1:
Most helpful comment
Actually, sorry... I see what you mean, the
inoperator, not thefor..inloop.I think what I was thinking, but conflated ideas and didn't articulate well in that paragraph, is that there's no built-in way to get all the properties from the whole prototype chain (which is what both forms of
indo). There's actually two different kinds of lists you might want to get: any existing property (theintest) or any enumerable property (thefor..inloop).If you wanted to get the any-property list (emulating the
inoperator), you're right, you'd want to use thegetOwnPropertyNames(..). If you wanted to get the enumerable-property list (emulating thefor..inloop), you'd want to useObject.keys(..).I should definitely clarify this paragraph in the second edition.