What is the equivalent of static methods in ColdFusion?

后端 未结 2 1649
有刺的猬
有刺的猬 2021-02-19 23:37

In C#, I created static methods to help me perform simple operations. For example:

public static class StringHelper
{
    public static string Reverse(string inp         


        
2条回答
  •  礼貌的吻别
    2021-02-20 00:13

    Nope, you are correct, there is no concept of static methods in ColdFusion. I think most would solve this problem through the use a singleton utilities in the application scope that are create when the application starts. So in your App.cfc in onApplication start you might have:

    
    

    Then when you needed to call it from anywhere you would use:

    
    

    Yeah, it's not as clean as static methods. Maybe someday we could have something like them. But right now I think this is as close as you will get.

提交回复
热议问题