簡體   English   中英

僅用於賦值的Javascript速記

[英]Javascript shorthand for assining a value only is variable exists

什么是JS的簡寫形式:

    if (typeof bfMax !== 'undefined') {
        options.max = bfMax;
    }

有條件地賦值的簡潔,易讀,可維護的簡寫為:

if (typeof bfMax !== 'undefined') {
    options.max = bfMax;
}

似乎您已經在使用它。

如果要縮小腳本使其更短,可讀性更差且難以維護,可以使用:

typeof bfMax!=='undefined'&&(options.max=bfMax)

當然,您需要換出變量名以使內容更簡短:

typeof b!=='undefined'&&(o.max=b)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM