|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
cfscript question
If the declaration of variables using var within cfscript isn't necessary,Jim McAtee 05/07/04 01:35 P Yeah, they're in the VARIABLES scope. There's really no difference betweenBarney Boisvert 05/07/04 01:43 P What makes you think it is isn't necessary? Any variable created inside aRaymond Camden 05/07/04 01:52 P > What makes you think it is isn't necessary?Jim McAtee 05/07/04 02:07 P > > What makes you think it is isn't necessary?Raymond Camden 05/07/04 02:14 P > > What makes you think it is isn't necessary?Barney Boisvert 05/07/04 02:19 P >>Required and necessary are two different things.Claude Schneegans 05/07/04 02:55 P Yes, the variables are in the variables scope. While it is not necessaryNathan Mische 05/07/04 01:49 P 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 ""; } 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 ----- 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.) > 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? > > 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. :) > > 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 >>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. 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 ""; } ________________________________
|
February 09, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||