It's not possible, any closure only has access to the variables in scope
when it is defined.
function foo(a,b,c,f)
{
var bar = function() {//has access to everything in foo}
function baz() {//Same as above}
}
var bash = function() { //Does not have access to what's in foo() at any
time}
foo(1,2,3,bash) //Doesn't suddenly give access to foo's locals.
Think of it this way - if what you wanted were possible, then what would
happen if I just invoked bash() instead of passing it to foo()?
There are tricks to achieve something similar to what you want, but they
require changing foo(), in which case you only need to pass arguments to the
f() function.
-Josh
On Sat, Feb 7, 2009 at 6:45 AM, Alex Harui aha...@adobe.com wrote:
I thought you said they were anonymous functions. Post a test case.
I'm not sure what you want to do is possible.
Alex Harui
Flex SDK Developer
Adobe Systems Inc. http://www.adobe.com/
Blog: http://blogs.adobe.com/aharui
*From:* flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] *On
Behalf Of *flexaustin
*Sent:* Friday, February 06, 2009 12:04 PM
*To:* flexcoders@yahoogroups.com
*Subject:* [flexcoders] Re: Getting at variables inside a function that
accepts a function
No as the functions are in separate classes and the var a, b, c, d are
private so in my class that calls the remote function I get Undefined
property a.
What about putting the vars in as params? Then I think there is a way
to access the params by order, correct?
So something like this to get at a in this example
public function acceptingFunction (func1:Function=null,
func2:Function=null):void{
var a:Number;
var b:String;
if(func1 func2){
if(func1(a=43))return true; --- inserting local param
anotherAcceptFunction(func2);
}
}
Then do this...
acceptFunction(function():void{ whatever code is to get at params by
order params[0]?});
--- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Alex
Harui aha...@... wrote:
I assume just using a,b,c,d didn't work?
Alex Harui
Flex SDK Developer
Adobe Systems Inc.http://www.adobe.com/
Blog: http://blogs.adobe.com/aharui
From: flexcoders@yahoogroups.com flexcoders%40yahoogroups.com [mailto:
flexcoders@yahoogroups.com flexcoders%40yahoogroups.com]
On Behalf Of flexaustin
Sent: Friday, February 06, 2009 8:55 AM
To: flexcoders@yahoogroups.com flexcoders%40yahoogroups.com
Subject: [flexcoders] Getting at variables inside a function that
accepts a function
How would I go about getting at variables of a function when I send in
an anonymous function so...
public function acceptingFunction (func1:Function=null,
func2:Function=null):void{
var a:Number;
var b:String;
if(func1 func2){
func1;
anotherAcceptFunction(func2);
}
}
public function anotherAcceptFunction(func:Function=null){
var c:Number;
var d:String;
if(func){
func
}
}
acceptFunction(function():void{get at vars a,b,c,d from here});
I really don't want to extend the orig. function if I can help it, in
this case extend the acceptingFunction, as its from some other library.
--
Therefore, send not to know For whom the bell tolls. It tolls for thee.
Josh 'G-Funk' McDonald
- j...@joshmcdonald.info
- http://twitter.com/sophistifunk
- http://flex.joshmcdonald.info/