p.c为什么等于37?p.c不在对象里,所以等于37。handler和proxy的用法

const handler = {
    
    
    get: function(obj, prop) {
    
    
        return prop in obj ? obj[prop] : 37;
    }
};

const p = new Proxy({
    
    }, handler);
p.a = 1;
p.b = undefined;

console.log(p.a, p.b);      // 1, undefined
console.log('c' in p, p.c); // false, 37

是这样吗?

猜你喜欢

转载自blog.csdn.net/weixin_40945354/article/details/120126564
37
今日推荐