简体   繁体   English

仅用于赋值的Javascript速记

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

What is a JS shorthand for the following: 什么是JS的简写形式:

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

The concise, readable, maintainable, shorthand for assigning a value conditionally is: 有条件地赋值的简洁,易读,可维护的简写为:

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

and it appears that you're already using it. 似乎您已经在使用它。

If you want to minify the script to make it shorter, less readable, and unmaintainable, you can use: 如果要缩小脚本使其更短,可读性更差且难以维护,可以使用:

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

Of course, you'll want to swap out your variable names to make things shorter: 当然,您需要换出变量名以使内容更简短:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM