House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

cfscript question

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jim McAtee
05/07/2004 01:35 PM

If the declaration of variables using var within cfscript isn't necessary, what kind of variables are being created?  Are they in the variables scope? For example, the variables 'sdatefmt' and 'edatefmt' in the cf function shown below: function DateRangeFormat(sdate, edate, mask, divider) {   if (IsDate(sdate)) sdatefmt = DateFormat(sdate, mask); else sdate = "";   if (IsDate(edate)) edatefmt = DateFormat(edate, mask); else edate = "";   if (Len(sdatefmt) and Len(edatefmt) and (sdatefmt is not edatefmt))     return sdatefmt & " " & divider & " " & edatefmt;   else if (Len(sdatefmt)) return sdatefmt;   else if (Len(edatefmt)) return edatefmt;   else return ""; }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
05/07/2004 01:43 PM

Yeah, they're in the VARIABLES scope.  There's really no difference between a CFSCRIPT function and a CFFUNCTION one, except that you can use tags, declare named optional arguments and do typechecking with CFFUNCTION.  Other than that, I believe the two are 100% equivalent. Cheers, barneyb ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
05/07/2004 01:52 PM

What makes you think it is isn't necessary? Any variable created inside a cfscript based function, or a cffunction based function, must be var scoped. Period. (Well, ok, yea, it works w/o the var scope, but leaving them off is very risky.)

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jim McAtee
05/07/2004 02:07 PM

> What makes you think it is isn't necessary? Because it isn't.  Period. > Any variable created inside a > cfscript based function, or a cffunction based function, must be var scoped. > Period. (Well, ok, yea, it works w/o the var scope, but leaving them off is > very risky.) You have to understand _why_ it's risky.  Not just "it's risky" and leave it at that. But it was a simple question.  If not declared, in which scope are the variables created?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
05/07/2004 02:14 PM

> > What makes you think it is isn't necessary? > > Because it isn't.  Period. I think I was very clear just a few words later that this was just my opinion. ----- Excess quoted text cut - see Original Post for more ----- Others had already answered where the variables get declared. I didn't think I had to speak down to him. ;) Point is - as the admin at cflib - I still see many submissions from folks who do not properly scope variables. I have no issue telling people they MUST var scope. Some things are worth being anal/overly strict/etc about. :)

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
05/07/2004 02:19 PM

> > What makes you think it is isn't necessary? > > Because it isn't.  Period. Required and necessary are two different things.  Using 'var' isn't required, but it is definitely necessary, at least in anything approaching normal circumstances. Cheers, barneyb

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude Schneegans
05/07/2004 02:55 PM

>>Required and necessary are two different things. In logic terms, they are not. >>Using 'var' isn't required, but it is definitely necessary, Let's say it's recommended, not required nor necessary, but highly recommended. -- _______________________________________ See some cool custom tags here: http://www.contentbox.com/claude/customtags/tagstore.cfm Please send any spam to this address: piegeacon@internetique.com Thanks.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Nathan Mische
05/07/2004 01:49 PM

Yes, the variables are in the variables scope. While it is not necessary to use the var statement, you probably want to for such things as loop counters and other local variables. http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/udfs12.htm <http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/udfs12.htm>; HTH --Nathan ________________________________   Sent: Friday, May 07, 2004 1:33 PM   To: CF-Talk   Subject: cfscript question         If the declaration of variables using var within cfscript isn't necessary,   what kind of variables are being created?  Are they in the variables   scope?      For example, the variables 'sdatefmt' and 'edatefmt' in the cf function   shown below:      function DateRangeFormat(sdate, edate, mask, divider) {     if (IsDate(sdate)) sdatefmt = DateFormat(sdate, mask); else sdate = "";     if (IsDate(edate)) edatefmt = DateFormat(edate, mask); else edate = "";     if (Len(sdatefmt) and Len(edatefmt) and (sdatefmt is not edatefmt))       return sdatefmt & " " & divider & " " & edatefmt;     else if (Len(sdatefmt)) return sdatefmt;     else if (Len(edatefmt)) return edatefmt;     else return "";   } ________________________________   


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

February 09, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29