one*_*ney 0 apache-flex flash actionscript-3
我在他的Book组件中遇到了Ely Greenfield的 SuperImage中的以下代码- 我理解loader.load()但其余的做了什么?
loader.load((newSource is URLRequest)? newSource:new URLRequest(newSource));
Run Code Online (Sandbox Code Playgroud)
它看起来像某种疯狂的内联if语句,但仍然,我有点预先准备好了.如果它是if语句 - 这种方式比常规if语句更好吗?
wor*_*ad3 11
?被称为"三元运算符",它的基本用途是:
(expression) ? (evaluate to this if expression is true) : (evaluate to this otherwise);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如果newSource是URLRequest,则loader.load将直接传递给newSource,否则将传递一个从newSource构建的新URLRequest.
三元运算符经常被用作if语句的更简洁形式,因为它允许ifs被内联.在这种情况下相应的代码将是:
if (newSource is URLRequest)
loader.load(newSource);
else
loader.load(new URLRequest(newSource));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1162 次 |
最近记录: |