UDFs have access to the local scope. So consider this:

<cfscript>
x = 1;

function foo() {
        writeOutput(x);
        x = x + 1;
        writeOutput(x);
}
</cfscript>

<cfoutput>#foo()#</cfoutput>

This will output 12 and will set x to 2. I could have also done
variables.x = variables + 1.

If you do NOT want to write to the local scope, you must use argumenets
or var scoped vars:


function doIt(x,y) {
        var z = 1;
}

In this example, x and y refer to arguments passed to the UDF and will
NOT overwrite any existing x or y var. Z is also local.


=======================================================================
Raymond Camden, Principal Spectra Compliance Engineer for Macromedia

Email    : [EMAIL PROTECTED]
Yahoo IM : morpheus

"My ally is the Force, and a powerful ally it is." - Yoda 

> -----Original Message-----
> From: Philip Arnold - ASP [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, January 30, 2002 8:47 AM
> To: CF-Community
> Subject: RE: UDF parameters and Scope
> 
> 
> > Err, I assume by 'local' you really mean Variables? The 
> answer is yes.
> > Consider this:
> >
> > <cfscript>
> > function foo() { return 1; }
> > </cfscript>
> >
> > <cfoutput>#variables.foo()#</cfoutput>
> 
> What I actually meant was variables inside the function, so
> 
> <cfscript>
> Function foo(var1)
> {myValue=variables.var1;
>  return (myValue+1);
> }
> </cfscript>
> 
> How do I refer to the parameters of a function? Which scope?
> 
> Philip Arnold
> Technical Director
> Certified ColdFusion Developer
> ASP Multimedia Limited
> T: +44 (0)20 8680 1133
> F: +44 (0)20 8686 7911
> 
> An ISO9001 registered company.
> 
> **********************************************************************
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> the system manager.
> **********************************************************************
> 
> 
> 
> 
______________________________________________________________________
Macromedia ColdFusion 5 Training from the Source
  Step by Step ColdFusion
  http://www.amazon.com/exec/obidos/ASIN/0201758474/houseoffusion

Archives: http://www.mail-archive.com/cf-community@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to