Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
-7
rated 0 times [  0] [ 7]  / answers: 1 / hits: 40782  / 16 Years ago, tue, march 10, 2009, 12:00:00

I have a function like



function a (p1, p2) { /* ... */ }


and in some scope want to get something like this:



function b (/* no params! */) { return a (my1, my2) }


where my1 and my2 are defined somehow in this scope. So I should get a parameterless function b, which when called calls a with fixed parameters my1 and my2. Now, the question is, why this is not right, and which is :)



UPD: Ok, I had some callbacks in those params, now found out, how to process them all. What I missed was to apply the technique twice. Thank you.


More From » function

 Answers
8

Just make a function that returns a new function b:



function getB(my1, my2) {
return function() {
a(my1, my2);
}
}


and use it like this:



var b = getB(my1, my2);

[#99870] Tuesday, March 3, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brendan

Total Points: 426
Total Questions: 110
Total Answers: 94

Location: Western Sahara
Member since Mon, May 3, 2021
3 Years ago
brendan questions
;