不存在值检测操作符

2022-10-13,,

使用形式: unsafe_expr?? 或 (unsafe_expr)??

这个操作符告诉我们一个值是否存在。基于这种情况, 结果是 true 或 false

访问非顶层变量的使用规则和默认值操作符(上一篇)也是一样的, 也就是说,可以写 product.color?? 和 (product.color)??

 

示例如下,假设并没有名为 mouse 的变量:

 

<#if mouse??>
  mouse found
<#else>
  no mouse found
</#if>
creating mouse...
<#assign mouse = "jerry">
<#if mouse??>
  mouse found
<#else>
  no mouse found
</#if>

 

将会输出:

 

  no mouse found
creating mouse...
  mouse found

 

《不存在值检测操作符.doc》

下载本文的Word格式文档,以方便收藏与打印。