猿问

这句JS能写的更简单吗?

options.async=options.async.toLowerCase()=='false'?false:true;

在phpstorm有个报错

        'options.async.toLowerCase()=='false'?false:true' can be simplified to    'options.async.toLowerCase()!='false'' 更少...    (Ctrl+F1)

This inspection reports any instances of JavaScript conditional      expressions of the form condition?true:false      or condition?false:true.      These expressions may be safely simplified to condition      or !condition , respectively. 

所以随便问

hhhzihao2
浏览 1589回答 1
1回答

习惯受伤

能,options.async=options.async.toLowerCase()=='false'?false:true;你这句的意思就是,当值等于false时,返回false,那么好了,当值不等于false时返回true,那么可以优化成:options.async=options.async.toLowerCase()!='false';
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答