I need a way to detect if prototype is built in JavaScript object (default prototype) as Object, Array, Date, Function etc.. Or is it custom user defined object.
Consider following code
const a = { a: 1 };
const b = Object.create(a);
const aProto = Object.getPrototypeOf(a); // Default prototype
const bProto = Object.getPrototypeOf(b); // User defined prototype
// One way to detect it would be
aProto === Object.prototype; // [true] we know it's default object
bProto === Object.prototype; // [false]
Above check would require to test for Array.prototype, Function.prototype, Date.prototype, etc...
Is there smarter way to achieve this?
Added
Context of what I'm trying to achieve. I want to modify object properties then I want to go over his prototype chain and do the same for objects on his prototype up until I reach the built in object that I want to skip without modifying.
In example from above I would modify all properties of object b then I would go to his prototype which is object a and modify all of his properties. Then I would go to prototype of a which is now built in object. I would like to detect that a have built in object as prototype and skip modifications.