hasOwnProperty 与 instanceof 有什么区别
参考答案
obj.hasOwnProperty(key):判断属性是否为对象自有(不含原型链),返回布尔;obj instanceof Ctor:判断构造函数的prototype是否出现在对象的原型链上,用于类型/继承关系判断。
const a = [];
'a'.length; // 自有
a instanceof Array; // true(原型链判断)
替代:Object.hasOwn(obj, k);类型判断更可靠的是 Array.isArray、Object.prototype.toString。