2

自定义标签具有属性范围。凉爽的。

我还看到了一些其他应用程序(可能还有 ColdBox?),开发人员将所有内容都放入属性结构中。例如在login.cfm

<cfparam name="attributes.username" default="some value">

除了必须指定attributes.foo哪些确实提高了可读性之外,还有什么意义,我承认,但为什么要重用完整范围的名称?

这是个人偏好还是我错过了属性范围的一些深刻的东西?

4

2 回答 2

5

It's nothing profound. A lot of frameworks (and individual developers) like to combine the form and url scopes into a single "event" object or something (ala your "attributes" example), but it doesn't really buy you much.

That said, naming a new object after an existing scope is misguided, and I'd recommend against it. What happens when you want something out of the attributes scope, not the attributes object?

You could always reference the object via variables.attributes.foo for explicitness, but that's a pain and a bit ugly. And of course, nothing stops you from accessing the attributes scope (scope priority would check attributes before variables.attributes), but then the person that has to read the code after you is more confused. It's essentially created a problem instead of solving one.

于 2012-11-20T15:56:50.187 回答
0

在 Fusebox 中,想法是单个文件可以用作框架的一部分,也可以用作 cfmodule 的一部分。corefiles/application.cfc 里面是:

...
<cfparam name="variables.attributes" default="#structNew()#" />
<cfif isDefined("URL")>
    <cfset structAppend(attributes,URL,true) />
</cfif>
<cfif isDefined("form")>
    <cfset structAppend(attributes,form,true) />
</cfif>
...

详见GitHub _

于 2012-11-28T19:43:43.203 回答