CFScript
![]() | This article needs more links to other articles to help integrate it into the encyclopedia. (January 2013) |
This article needs additional citations for verification. (November 2006) |
CFScript is an extension of CFML on the ColdFusion platform. CFScript resembles JavaScript. Some ColdFusion developers prefer it since it has less visual and typographical overhead than ordinary CFML; It is considered best practice to write Coldfusion Components and all business logic in CFScript and to use CFML only in .cfm files amongst HTML.
Usage
All CFScript code must be contained within a CFScript tag pair, as follows:
<cfscript> xParam = 115; yParam = 200; color = 'FFCC99'; </cfscript>
Simple component example in cfscript, containing two function
component { public void function foo(){ WriteOutput("Method foo() called<br>"); } public function getString(){ var x = "hello"; return x; } }
While many ColdFusion tags have exact CFScript analogies, there are quite a few tags that do not. These include both complex tags that would be difficult to duplicate and simple tags that are easy to imitate (using ColdFusion UDF's):
Complex:
<cfquery> <cffile> <cfdirectory>
Simple:
<cfdump> <cfthrow>
While there may not be direct substitutions for all tags, it is often still possible to achieve the results of a tag in script, but via a different syntax. For example this is how to get a query into a variable in CFSCRIPT without writing a UDF:
<cfscript> qGetData = new Query(); qGetData .setDataSource('#APPLICATION.datasource#'); qGetData .setSQL('SELECT column1, column2 FROM table WHERE 1'); qDateResult = qGetData .Execute().getResult(); </cfscript>
Syntax
Since Coldfusion 8 cfscript has supported syntax abbreviations that are common in many other programming languages, such as "++", "<=" and "+=".[1]
References
External links