Content deleted Content added
SimLibrarian (talk | contribs) m rm contraction Tags: Mobile edit Mobile app edit iOS app edit App section source |
|||
(20 intermediate revisions by 16 users not shown) | |||
Line 1:
{{
'''CFScript''' is an extension of [[ColdFusion Markup Language|CFML]] on the ColdFusion platform. CFScript resembles [[JavaScript]]. Some ColdFusion [[Software Developers|developers]] prefer it since it has less visual and typographical overhead than ordinary CFML.{{Clarify|reason=|date=March 2020}}
== Usage ==
Unless it is within a pure script-based ColdFusion Component, all CFScript code must be contained within a CFScript tag pair as follows:
<syntaxhighlight lang="cfm">
<cfscript>
</cfscript>
</syntaxhighlight>
A simple example of a [[Subroutine|function]]:
<syntaxhighlight lang="cfm">
<cfscript>
function Sum(a, b) {
var sum = a + b;
return sum;
}
</cfscript>
</syntaxhighlight>
<syntaxhighlight lang="javascript">
public void function foo()
WriteOutput("Method foo() called
}
public function getString()
var x = "hello";
return x;
}
}
</syntaxhighlight>
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 [[User-defined function|UDF]]:
<syntaxhighlight lang="cfm">
<cfscript>
</cfscript
</syntaxhighlight>
== Syntax ==▼
Since
▲==Syntax==
▲Since Coldfusion 8 cfscript has supported syntax abbreviations that are common in many other programming languages, such as "++", "<=" and "+=".<ref>Nadel, Ben. http://www.bennadel.com/blog/741-Learning-ColdFusion-8-All-Hail-The-New-Operator.htm</ref>
=== Arithmetic operators ===
{| class="wikitable"
Line 83 ⟶ 82:
=== Comments ===
CFScript has two forms of comments: single line and multiline.
<syntaxhighlight lang="javascript">
</syntaxhighlight>
<syntaxhighlight lang="javascript">
/*
</syntaxhighlight>
=== Try /
<syntaxhighlight lang="javascript">
try {
} catch (any e) {
} finally {
}
</syntaxhighlight>
=== Switch statement ===
<syntaxhighlight lang="javascript">
switch (car) {
case "Nissan":
WriteOutput("I own a Nissan");
Line 113 ⟶ 114:
WriteOutput("I own a Toyota");
break;
default:
WriteOutput("I'm exotic");
}
</syntaxhighlight>
=== Looping ===
==== For
<syntaxhighlight lang="javascript">
for (i=1; i
}
</syntaxhighlight>
==== FOR IN Loop ====
<syntaxhighlight lang="javascript">
struct = StructNew();
struct.one = "1";
struct.two = "2";
for (key in struct) {
}
//OUTPUTS onetwo
</syntaxhighlight>
==== While
<syntaxhighlight lang="javascript">
x = 0;
while (x
}
//
</syntaxhighlight>
==== Do /
<syntaxhighlight lang="javascript">
x = 0;
do {
} while (x
//
</syntaxhighlight>
==== Looping over an
<syntaxhighlight lang="javascript">
for (item in array) {
doSomething(item);
}
</syntaxhighlight>
== Differences from JavaScript ==
Although CFScript and JavaScript are similar, they have several key differences. The following list identifies CFScript features that differ from JavaScript:
* CFScript uses ColdFusion
*[[Variable declaration|Variable declarations]] (var keyword) are only used in user-defined functions and threads.
* CFScript is not case sensitive.
* All statements end with a semicolon, and line breaks in the code are ignored.
* Assignments are statements, not expressions, and therefore cannot be used in situations that require evaluating the assignment operation.
* JavaScript objects, such as
* Only the ColdFusion server processes CFScript. There is no client-side CFScript.
== References ==▼
▲==References==
{{Reflist}}
== External links ==
* [http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7feb.html Extending ColdFusion Pages with CFML Scripting - Adobe]
* [https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/extending-coldfusion-pages-with-cfml-scripting.html]
{{DEFAULTSORT:Cfscript}}
[[Category:CFML programming language]]
[[Category:Scripting languages]]
|