Javascript (0 && 1)
Javascript (0 && 1)
我正在尝试调试一些 JavaScript 与 Dojo 本地化相关的代码,我在 Dojo 中遇到了以下代码:
isXd = function(mid, contextRequire){
return ( 0 && 1 ) ?
contextRequire.isXdUrl(require.toUrl(mid + ".js")) :
true;
},
这里的三目运算符有什么用?在我看来 (0 && 1)
总是 false
而这个函数总是 return true
。这是浏览器兼容性问题吗?
我发现的源代码与您的代码略有不同,但解释应该合适。
原始代码可以在i18n.js中找到,它是完整源代码包的一部分:
isXd = function(mid, contextRequire){
return (has("dojo-sync-loader") && has("dojo-v1x-i18n-Api")) ?
contextRequire.isXdUrl(require.toUrl(mid + ".js")) :
true;
},
i18n.js.uncompressed.js 中包含在 release 包中的相同部分如下所示:
isXd = function(mid, contextRequire){
return ( 1 && 1 ) ?
contextRequire.isXdUrl(require.toUrl(mid + ".js")) :
true;
},
当您查看 Dojo Loader 部分 "Options/Features" 时,您会看到 dojo-sync-loader
有一个默认值 true
.
文档指出:
The first column is the Option/Feature as defined within the loader, the second options is whether this is a detected feature (via has.add()) or if it is just an option and its default value. With “unbuilt” source, all the features and options are available. If the loader has been built, then some of these features may have been set as staticHasFeatures and not be configurable anymore.
由于 dojo-sync-loader
是一个不可检测的功能,可能会在内置源代码中替换它。
我正在尝试调试一些 JavaScript 与 Dojo 本地化相关的代码,我在 Dojo 中遇到了以下代码:
isXd = function(mid, contextRequire){
return ( 0 && 1 ) ?
contextRequire.isXdUrl(require.toUrl(mid + ".js")) :
true;
},
这里的三目运算符有什么用?在我看来 (0 && 1)
总是 false
而这个函数总是 return true
。这是浏览器兼容性问题吗?
我发现的源代码与您的代码略有不同,但解释应该合适。
原始代码可以在i18n.js中找到,它是完整源代码包的一部分:
isXd = function(mid, contextRequire){
return (has("dojo-sync-loader") && has("dojo-v1x-i18n-Api")) ?
contextRequire.isXdUrl(require.toUrl(mid + ".js")) :
true;
},
i18n.js.uncompressed.js 中包含在 release 包中的相同部分如下所示:
isXd = function(mid, contextRequire){
return ( 1 && 1 ) ?
contextRequire.isXdUrl(require.toUrl(mid + ".js")) :
true;
},
当您查看 Dojo Loader 部分 "Options/Features" 时,您会看到 dojo-sync-loader
有一个默认值 true
.
文档指出:
The first column is the Option/Feature as defined within the loader, the second options is whether this is a detected feature (via has.add()) or if it is just an option and its default value. With “unbuilt” source, all the features and options are available. If the loader has been built, then some of these features may have been set as staticHasFeatures and not be configurable anymore.
由于 dojo-sync-loader
是一个不可检测的功能,可能会在内置源代码中替换它。