Open DamomHd opened 3 years ago
var a = {
value: 0,
valueOf: function() {
this.value++;
return this.value;
}
};
console.log(a == 1 && a == 2 && a == 3); //true
var a = [1, 2, 3]
a.join = a.shift
console.log(a == 1 && a == 2 && a == 3)
function a() {};
a.count = 0;
a.toString = function() {
return ++this.count;
}
console.log(a == 1 && a == 2 && a == 3);
(function init(vlaue = 0) {
Object.defineProperty(globalThis, 'a', {
get: () => ++vlaue
});
})();
console.log(a === 1 && a === 2 && a === 3);
此题涉及到对象砖原始类型是根据什么流程运行的
对象转原始类型,会调用内置的[ToPrimitive]函数,对于该函数而言,其逻辑如下