代码之家  ›  专栏  ›  技术社区  ›  Henry

在CF9中编写CFC的编码约定?

  •  6
  • Henry  · 技术社区  · 5 年前

    随着在cf9中编写cfc的新方法的出现,cf9中有哪些新的编码约定?

    这里有一些我能想到的…

    3 回复  |  直到 12 年前
        1
  •  2
  •   Alex    15 年前

    对于脚本样式的cfc中的组件和函数,我们还需要设置属性output=false吗?

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

        2
  •  0
  •   Mike Causer    13 年前

    如果您使用“new my.cfc()”语法调用它,那么init()方法不必返回“this”范围。真实故事。

    如果您在一个cfc中并且想要设置一个属性,不要使用这个.setfoo(),只需转到setfoo()。 getfoo()也是如此。 这个.xxx()就像从前门出去,却又回来了。此外,您的access=private自定义getter和setter不会工作,因为函数不在这个范围内。

    “var foo”与“local.foo”-就我个人而言,我更喜欢var'd变量,因为有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;
    }
    
        3
  •  -1
  •   James A Mohler    12 年前

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

    推荐文章