为什么 writedump 函数不需要在 cfscript 中使用分号?
通常,CFSCRIPT 标记中编写的所有语句都必须以半色 (;) 结尾,但今天我正在处理示例代码,我忘记在 writedump() 函数之后编写分号 (;),但代码仍然执行良好。下面是示例代码,这可以很好地工作;在声明的末尾。只是好奇为什么 writeDump 可以在没有分号的情况下工作。
我正在使用 Coldfusion 版本 9,0,1,274733。
<cfscript>
a = "Hello";
b = "World";
concat(a,b);
writeDump(a & b)
writeOutput(a);
</cfscript>
<cffunction name="concat" access="public" output="false" returntype="string">
<cfargument name="str1" required="true" type="string" />
<cfargument name="str2" required="true" type="string" />
<cfreturn str1 & str2>
</cffunction>
Normally all statement written in CFSCRIPT tag must end with semicolor (;) but today I was working with sample code where I forgot to write semicolon (;) after writedump() function but still code execute fine. Se below sample code and this work fine with ; at the end of statement. Just curios to know why writeDump work without semicolon.
I am working with Coldfusion version 9,0,1,274733.
<cfscript>
a = "Hello";
b = "World";
concat(a,b);
writeDump(a & b)
writeOutput(a);
</cfscript>
<cffunction name="concat" access="public" output="false" returntype="string">
<cfargument name="str1" required="true" type="string" />
<cfargument name="str2" required="true" type="string" />
<cfreturn str1 & str2>
</cffunction>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜 Adobe 开发人员可能忘记将这个非常无用的约定应用于 CFScript 解析器......因为它看起来像一个错误(它是 已经提交,顺便说一句),真的。你甚至可以写这样的东西,它会起作用:
此函数的隐式分号。
值得一提的是,Railo 更进一步,当在线出现单个语句时,所有分号都是可选的,因此这将工作得很好:
I guess Adobe devs could forgot to apply this pretty useless convention to the CFScript parser... Because it looks like a bug (it is already filed, btw), really. You can even write something like this and it will work:
Kind of implicit semicolon for this function.
It worth mentioning that Railo went further and made all semicolons optional when single statement present on line, so this will work just fine: