Although I have a good understanding of prototypes, I encountered some confusion when I attempted the following:
var obj = {};
Object.setPrototypeOf(obj, Array.prototype);
console.log(Array.isArray(obj)); // false?
What's even more perplexing:
var arr = [];
Object.setPrototypeOf(arr, Object.prototype);
console.log(Array.isArray(arr)); // true?? 8-{
After conducting some research, I learned that Array.isArray
actually searches for a hidden property within the object: [[DefineOwnProperty]].
Is this property completely immutable on an existing object? Or is it possible for a regular object {}
to be modified in a way that calling Array.isArray
on it would yield true
?