V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zxkmm
V2EX  ›  TypeScript

遇到了极其诡异的不符合进入 if 条件的要求但是还是进入了

  •  
  •   zxkmm · 95 天前 · 949 次点击
    这是一个创建于 95 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码

        addFrontLine(_line_location_, _padding_, _border_) {
    
            console.log(_padding_);
            console.log(_line_location_);
    
            if (_padding_ >= _line_location_) {
    
                _padding_ = _line_location_
    
            }
    
            console.log(_padding_);
            console.log(_line_location_);
    
            const css = `
    
            .layout-tab-container .b3-list-item > .b3-list-item__toggle {
                padding-left: 4px !important;
            }
    
            .layout-tab-container ul ul:before {
                content: "";
                position: absolute;
                top: 0;
                bottom: 0;
                left: ${_line_location_}px;
                border-left: ${_border_}px solid var(--b3-theme-background-light);
            }
            
            .layout-tab-container ul ul {
                position: relative;
                padding-left: ${_padding_}px;
            }
            
            `
            this.applyStyles(css);
        }
    

    执行后控制台输出的值

    6
    20
    20
    20
    

    如果把 if 语句注释掉,就恢复正常了。 有没有大佬帮看看是什么原因? 完整代码 https://github.com/zxkmm/siyuan_doctree_compress/blob/13f1b3cda6c721001c1c33ab449e6321bc791807/src/index.ts#L118

    第 1 条附言  ·  95 天前
    抱歉抱歉,第一次写动态类型的语言,一下子没反应过来
    3 条回复    2024-01-23 21:24:52 +08:00
    finab
        1
    finab  
       95 天前
    你打印下变量类型,如果 if 走了,那肯定不是数值类型,说不定是俩字符串呢
    zxkmm
        2
    zxkmm  
    OP
       95 天前
    @finab 感谢,问题找到了,我好笨
    zxkmm
        3
    zxkmm  
    OP
       95 天前
    见谅见谅,第一次写动态类型的语言
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5405 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:38 · PVG 16:38 · LAX 01:38 · JFK 04:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.