By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,654 IT Pros & Developers. It's quick & easy.

Closures with functions as parameters

P: 62
Hi,

Could anyone explain what happens when some function (x) is passed as a parameter into a function (b) which is nested inside a function(a), i.e.
Expand|Select|Wrap|Line Numbers
  1. a=function()
  2. {
  3.   b=function(t)
  4.   {
  5.     // what scope chain does t have in here?
  6.   };
  7.   b(x); // where x is some random function that could be externally defined.
  8. };
Sep 27 '11 #1

✓ answered by Dormilich

hm, I don’t see anything special (functions are like any other variables) so I’d say the standard rules apply.

edit: btw, you code is not a closure.

Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
hm, I don’t see anything special (functions are like any other variables) so I’d say the standard rules apply.

edit: btw, you code is not a closure.
Sep 27 '11 #2

P: 62
Thanks for clarifying. I originally thought that running the parameter t as a function inside b would allow me to get to the variables inside a, or perhaps if t returns a function, that function would inherit the variables inside a. However, after some testing, I have found that it is incorrect.
Sep 30 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.