有了 CF9 中编写 CFC 的新方法,CF9 有哪些新的编码约定?

这是我能想到的一些...

有帮助吗?

解决方案

我们还需要为脚本风格CFC中的组件和函数设置属性output=false吗?

我不这么认为。 <cfscript> 本质上抑制任何空白和需求 writeOutput() 为了有任何输出。

其他提示

如果您使用“new my.cfc()”语法调用 init() 方法,则不必返回“this”作用域。真实的故事。

如果您在 cfc 中并且想要设置属性,请不要使用 this.setFoo(),只需使用 setFoo() 即可。getFoo() 也是如此。this.xxx() 就像走出前门却又回来了。此外,您的 access=private 自定义 getter 和 setter 将无法工作,因为函数不会在此范围内。

“var foo”与“local.foo” - 就我个人而言,我更喜欢 var 变量,因为 a) 需要输入的代码更少,b) 需要阅读的代码更少。

// there isnt a huge difference here
var today = now();
var tomorrow = dateAdd( 'd', 1, today );
local.today = now();
local.tomorrow = dateAdd( 'd', 1, local.today );

// but when you start getting more complex examples, it quickly blows out
var out = method( var1, var2, var3, var4, var5 );
local.out = method( local.var1, local.var2, local.var3, local.var4, local.var5 );

使用 javadocs 风格的注释。文档是你的朋友。

/**
* @hint This is a hint for the whole function
* @arg1 This is an argument hint
* @arg2 This is another argument hint
**/
public void function myFunction( string arg1 = 'default', boolean arg2 ) {
    return true;
}

所有更改数据的函数都应该返回某个值,即使它是当前始终为 true 的布尔值。函数最终需要返回 false

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top