function abc(a) {
'use strict';
a = (a !== undefined) ? a : 'GET';
}
为什么会抛出如下异常?(不是错误,是不符合规范JSLint)
Expected '?' at column 8, not column 26.
a = (a !== undefined) ? a : 'GET';
line 2 column 30Expected ':' at column 8, not column 30.
a = (a !== undefined) ? a : 'GET';
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
JSLint对空白符(缩进)有明确规定
三元操作符的
?和:要换新行并增加4个空格的缩进。所以它要求?在第8列,:同理。所以正确的写法是:
试了下,没有错啊,楼主再检查下呢
试了下,没有报错。
楼主的初衷如果是想判断
a是否存在,不存在设置默认值,可以这样写这样可读性会好很多。