什么时候var在ColdFusion组件中的变量? [英] When to var scope your variables in ColdFusion components?

查看:157
本文介绍了什么时候var在ColdFusion组件中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(a)什么情况下应该变量范围变量和(b)什么情况下你不应该在ColdFusion组件中的var范围?

(a) What cases should you var scope variables and (b) what cases should you not var scope in a ColdFusion components?

推荐答案

当你在CFC中实现一个在多个请求之间共享的函数,Service CFC's in Application scope)

You should var scope your variables when you're implementing a function inside a CFC that is shared across multiple requests (i.e. Singleton, Service CFC's in Application scope)

如果CFC每次都被实例化,你不需要(但仍然强烈推荐)var scope你的变量,而你的方法不是在同一个CFC中调用另一个方法,可以访问您在调用方法中定义的vars。例如,您通过Web服务或ajax直接调用的远程方法,它不会调用其他使用您不是var范围的vars的方法,也不会调用CFWheels中的Controller。

You don't need to (yet still highly recommended to) var scope your variables if the CFC is instantiated every time, AND your method is not calling another method in the same CFC that may access the vars you've defined in the caller method. Such as a remote method that you called directly through web service or ajax, which doesn't call other methods that make use of vars you didn't var scope, or Controller in CFWheels.

你应该总是使用var关键字定义函数局部变量。每个CFC变量和范围doc http://livedocs.adobe .com / coldfusion / 8 / htmldocs / help.html?content = buildingComponents_29.html

"You should always define function-local variables using the var keyword." per CFC variables and scope doc http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=buildingComponents_29.html

这篇关于什么时候var在ColdFusion组件中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆