CFScript
   HOME

TheInfoList



OR:

CFScript is an extension of
CFML ColdFusion Markup Language, more commonly known as CFML, is a scripting language for web development that runs on the JVM, the .NET framework, and Google App Engine. Multiple commercial and open source implementations of CFML engines are availab ...
on the ColdFusion platform. CFScript resembles
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
. Some ColdFusion developers prefer it since it has less visual and typographical overhead than ordinary CFML.


Usage

Unless it's within a pure script-based ColdFusion Component, all CFScript code must be contained within a CFScript tag pair as follows: xParam = 115; yParam = 200; color = 'FFCC99'; A simple example of a
function Function or functionality may refer to: Computing * Function key, a type of key on computer keyboards * Function model, a structured representation of processes in a system * Function object or functor or functionoid, a concept of object-oriente ...
: function Sum(a, b) A simple example of a component in CFScript, containing two functions: component ColdFusion 11,
Railo Railo Server, commonly referred to as Railo ( ), is open source software which implements the general-purpose CFML server-side scripting language, often used to create dynamic websites, web applications and intranet systems. CFML is a dynami ...
4.1+, and
Lucee Lucee is an open source implementation of a lightweight dynamically-typed scripting language for the Java virtual machine (JVM). The language is used for rapid development of web applications that compile directly to Java bytecode, and is comp ...
4.5+ both do their best to fully support cf tags in CFScript. 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: qGetData = new Query(); qGetData.setDataSource('#Application.datasource#'); qGetData.setSQL('SELECT column1, column2 FROM table WHERE 1'); qDateResult = qGetData.Execute().getResult();


Syntax

Since ColdFusion 8, CFScript has supported
syntax In linguistics, syntax () is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure ( constituency) ...
abbreviations that are common in many other programming languages, such as "++", "<=" and "+=".


Arithmetic operators


Comments

CFScript has two forms of comments: single line and multiline. // This is a single-line comment. // This is a second single-line comment. /* This is a multiline comment. You do not need to start each line with a comment indicator. This line is the last line in the comment. */


Try / Catch

try catch (any e) finally


Switch statement

switch (car)


Looping


For Loop

for (i=1; i <= ArrayLen(array); i=i+1)


FOR IN Loop

struct = StructNew(); struct.one = "1"; struct.two = "2"; for (key in struct) //OUTPUTS onetwo


While Loop

x = 0; while (x < 5) // Outputs: 12345


Do / While Loop

x = 0; do while (x <= 0); // Outputs: 1


Looping over an Array

for (item in array)


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
expression Expression may refer to: Linguistics * Expression (linguistics), a word, phrase, or sentence * Fixed expression, a form of words with a specific meaning * Idiom, a type of fixed expression * Metaphorical expression, a particular word, phrase, o ...
, which are not a superset or a subset of JavaScript expressions. In particular, ColdFusion expressions do not support
bitwise operators In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operat ...
, and the ColdFusion MOD or % operator operates differently from the corresponding JavaScript % operator: In ColdFusion, the operator does integer arithmetic and ignores fractional parts. ColdFusion expressions also support the EQV, IMP, CONTAINS, and DOES NOT CONTAIN operators that are not supported in JavaScript. * 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 window and document, are not available. * Only the ColdFusion server processes CFScript. There is no client-side CFScript.


References


External links


Extending ColdFusion Pages with CFML Scripting - Adobe


{{DEFAULTSORT:Cfscript CFML programming language Scripting languages