在 ColdFusion 中使用带有命名参数的冒号 [英] Using a colon with named arguments in ColdFusion
问题描述
我在一段录音中看到了这个代码示例,想知道冒号语法的作用.我搜索了文档,但找不到任何信息:
I saw this code example in a recording and wanted to know what the colon syntax did. I searched the docs, but I wasn't able to find any info on it:
weather.subscribe(observer: application.observers.currentConditions);
我知道我们可以在 CF9 中为三元运算符使用冒号:
I know we can use colon in CF9 for ternary operators:
result = (条件) ?真:假;
但在这种情况下,它看起来像是被用来提供命名参数;那么它在那里做什么呢?
But in this case it looks like it's being used to provide named arguments; so what's it doing there?
推荐答案
<cfset result = obj.func(arg:value,thing:42)/>
我看了这个然后眨眼,眨眼...这不可能!你不能使用冒号命名参数!呃,可以吗?好吧,显然你可以.
<cfset result = obj.func(arg:value,thing:42) />
I looked at this and went blink, blink... That can't be right! You can't use colons for named arguments! Er, can you? Well, apparently you can.
http://corfield.org/blog/post.cfm/Learn_something_new_every_day_named_arguments
这篇关于在 ColdFusion 中使用带有命名参数的冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!