根据咖啡脚本网站
console.log(s) if s?
Run Code Online (Sandbox Code Playgroud)
应该生成
if (typeof s !== "undefined" && s !== null) {
console.log(s);
}
Run Code Online (Sandbox Code Playgroud)
但是我的浏览器中出现的是什么
if (s != null) {
return console.log(s);
}
Run Code Online (Sandbox Code Playgroud)
使用coffee-script-source(1.6.2),coffee-rails(3.2.2),rails-backbone(0.7.2),rails(3.2.13)
这是我的咖啡脚本功能.任何想法为什么我没有得到什么咖啡脚本网站说我应该?
window.p = (s) ->
console.log(s) if s?
Run Code Online (Sandbox Code Playgroud) 所以我正在玩咖啡脚本并得到这种行为:
a?
将转化为typeof a !== "undefined" && a !== null;
- 那没关系
问题是如果我尝试相同的a.foo?
.这次它转化为a.foo != null;
我得到的相同结果a[foo]
.
是否有"快速"的方法来检查是否a.foo
为null或未定义,如有?