繁体   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