<tfoot id='N3Q0a'></tfoot>

    1. <small id='N3Q0a'></small><noframes id='N3Q0a'>

      <i id='N3Q0a'><tr id='N3Q0a'><dt id='N3Q0a'><q id='N3Q0a'><span id='N3Q0a'><b id='N3Q0a'><form id='N3Q0a'><ins id='N3Q0a'></ins><ul id='N3Q0a'></ul><sub id='N3Q0a'></sub></form><legend id='N3Q0a'></legend><bdo id='N3Q0a'><pre id='N3Q0a'><center id='N3Q0a'></center></pre></bdo></b><th id='N3Q0a'></th></span></q></dt></tr></i><div id='N3Q0a'><tfoot id='N3Q0a'></tfoot><dl id='N3Q0a'><fieldset id='N3Q0a'></fieldset></dl></div>

      1. <legend id='N3Q0a'><style id='N3Q0a'><dir id='N3Q0a'><q id='N3Q0a'></q></dir></style></legend>
          <bdo id='N3Q0a'></bdo><ul id='N3Q0a'></ul>

        ColdFusion 中静态方法的等价物是什么?

        时间:2023-06-05

          <bdo id='aarZ6'></bdo><ul id='aarZ6'></ul>
              1. <i id='aarZ6'><tr id='aarZ6'><dt id='aarZ6'><q id='aarZ6'><span id='aarZ6'><b id='aarZ6'><form id='aarZ6'><ins id='aarZ6'></ins><ul id='aarZ6'></ul><sub id='aarZ6'></sub></form><legend id='aarZ6'></legend><bdo id='aarZ6'><pre id='aarZ6'><center id='aarZ6'></center></pre></bdo></b><th id='aarZ6'></th></span></q></dt></tr></i><div id='aarZ6'><tfoot id='aarZ6'></tfoot><dl id='aarZ6'><fieldset id='aarZ6'></fieldset></dl></div>
                • <legend id='aarZ6'><style id='aarZ6'><dir id='aarZ6'><q id='aarZ6'></q></dir></style></legend>
                  <tfoot id='aarZ6'></tfoot>

                    <tbody id='aarZ6'></tbody>

                  <small id='aarZ6'></small><noframes id='aarZ6'>

                  本文介绍了ColdFusion 中静态方法的等价物是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  在 C# 中,我创建了静态方法来帮助我执行简单的操作.例如:

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

                  public static class StringHelper
                  {
                      public static string Reverse(string input)
                      {
                          // reverse string
                          return reversedInput;
                      }
                  }
                  

                  然后在控制器中,我会通过简单地使用来调用它:

                  Then in a controller, I would call it by simply using:

                  StringHelper.Reverse(input);
                  

                  现在我将 ColdFusion 与 Model Glue 一起使用,我想做同样的事情.但是,ColdFusion 中似乎没有静态方法的概念.如果我这样创建 CFC:

                  Now I'm using ColdFusion with Model Glue, and I'd like to do the same thing. However, it seems like there's no concept of static methods in ColdFusion. If I create a CFC like this:

                  component StringHelper
                  {
                      public string function Reverse(string input)
                      {
                          // reverse string
                          return reversedInput;
                      }
                  }
                  

                  我只能通过在控制器中创建 StringHelper 的实例来调用此方法吗,如下所示:

                  Can I only call this method by creating an instance of StringHelper in the controller, like this:

                  component Controller
                  {
                      public void function Reverse()
                      {
                          var input = event.getValue("input");
                          var stringHelper = new StringHelper();
                          var reversedString = stringHelper.Reverse(input);
                          event.setValue("reversedstring", reversedString);
                      }
                  }
                  

                  或者是否有一些地方可以放置框架将在幕后创建一个实例的静态"CFC,这样我就可以像静态一样使用它,有点像 helpers 文件夹的工作原理?

                  Or is there some place where I can put 'static' CFCs that the framework will create an instance of behind the scenes so I can use it as if it was static, kind of like how the helpers folder works?

                  推荐答案

                  不,你是对的,ColdFusion 中没有静态方法的概念.我认为大多数人会通过在应用程序启动时创建的应用程序范围内使用单例实用程序来解决这个问题.所以在你的 App.cfc 中 onApplication 开始你可能有:

                  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:

                  <cfset application.StringHelper = createObject("component", "path.to.StringHelper") />
                  

                  然后当你需要从任何你会使用的地方调用它时:

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

                  <cfset reversedString = application.StringHelper.reverse(string) />
                  

                  是的,它不像静态方法那样干净.也许有一天我们可以拥有类似的东西.但现在我认为这是你将得到的最接近的.

                  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.

                  这篇关于ColdFusion 中静态方法的等价物是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:未找到方法使用 ColdFusion 中的列表调用 .NET 方法 下一篇:作为 ColdFusion 开发人员,您应该如何学习 ASP.NE

                  相关文章

                  最新文章

                • <tfoot id='0TJvY'></tfoot>

                  1. <legend id='0TJvY'><style id='0TJvY'><dir id='0TJvY'><q id='0TJvY'></q></dir></style></legend>
                      <bdo id='0TJvY'></bdo><ul id='0TJvY'></ul>

                    1. <i id='0TJvY'><tr id='0TJvY'><dt id='0TJvY'><q id='0TJvY'><span id='0TJvY'><b id='0TJvY'><form id='0TJvY'><ins id='0TJvY'></ins><ul id='0TJvY'></ul><sub id='0TJvY'></sub></form><legend id='0TJvY'></legend><bdo id='0TJvY'><pre id='0TJvY'><center id='0TJvY'></center></pre></bdo></b><th id='0TJvY'></th></span></q></dt></tr></i><div id='0TJvY'><tfoot id='0TJvY'></tfoot><dl id='0TJvY'><fieldset id='0TJvY'></fieldset></dl></div>
                    2. <small id='0TJvY'></small><noframes id='0TJvY'>