是Node.js中的JavaScript,与浏览器(Chrome)不同



相同 .jade文件中我有:

script.
  if (user)
    ...//using jQuery to change color theme

以及:

li
-if (user)
  a(href='/lougout')
-else
  a(href='/login')

如果不存在user,则第一个在Chrome中导致以下错误:

未经参考的参考:未定义用户

第二个完全没有问题的作用,即Node.js Server/Jade Engine不抱怨。

为什么这样发生?

script之后的 .表示其内容是字面的。if (user)发射到<script>中,未评估:

<script>
if (user)
  ... // using jQuery to change color theme
</script>

相关内容

最新更新