xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js logical or assignment bug All In One

js logical or assignment bug All In One

js || bug All In One

const list = [
    {
        "value": "INVENTORY_FEED",
        "name": "NEWS",
    },
    {
        "value": "INVENTORY_VIDEO_FEED",
        "name": "视频",
    },
    {
        "value": "INVENTORY_TOMATO_NOVEL",
        "name": "小说",
    },
    {
        "value": "INVENTORY_UNION_SLOT",
        "name": "穿山甲",
    },
    {
        "value": "UNION_BOUTIQUE_GAME",
        "name": "游戏",
    }
];



bug ❌


list.forEach(item => {
    // 因为: ('INVENTORY_UNION_SLOT' || 'UNION_BOUTIQUE_GAME') === 'INVENTORY_UNION_SLOT'
    // 所以: item.value === ('INVENTORY_UNION_SLOT' || 'UNION_BOUTIQUE_GAME') =>  item.value === 'INVENTORY_UNION_SLOT' ❌
    if (item.value === ('INVENTORY_UNION_SLOT' || 'UNION_BOUTIQUE_GAME')) {
        // console.log('item', item);
        // console.log('?', item.value === ('INVENTORY_UNION_SLOT' || 'UNION_BOUTIQUE_GAME'));
        // console.log('???', (item.value === 'INVENTORY_UNION_SLOT' || item.value === 'UNION_BOUTIQUE_GAME'));
        Object.assign(item, {
            disabled: true,
        });
    };
});

solution ✅


list.forEach(item => {
    if (item.value === 'INVENTORY_UNION_SLOT' || item.value === 'UNION_BOUTIQUE_GAME') {
        Object.assign(item, {
            disabled: true,
        });
    };
});

refs

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-11-30 11:11  xgqfrms  阅读(33)  评论(0编辑  收藏  举报