var rF = function(callback) {
alert("there2222");
//additional calls
$(document).trigger("lc", [callback]);
};
var pSl = function(callback) {
var func = pSR; // how to pass callback parameter in function
rF(func);
};
var pSR = function(callback, vars) {
alert(callback);
alert(vars);
};
$(document).on("lc", function(e, callback) {
alert("theaaa");
alert(callback, "ssss");
});
$('img').click(function() {
pSl("lol");
});
Asked
Active
Viewed 97 times
0

tmarwen
- 15,750
- 5
- 43
- 62

Kunal Vashist
- 2,380
- 6
- 30
- 59
-
pS1 is probably not visible to your jquery function. – brso05 Sep 22 '14 at 15:29
-
try defining function without assigning to variable just a separate declaration for each function ex. function pS1(callback){} – brso05 Sep 22 '14 at 15:30
-
Do the definition before the jquery call – brso05 Sep 22 '14 at 15:31
-
i need to pass this callback to other method – Kunal Vashist Sep 22 '14 at 15:31
-
can you provide me snippet what exactly you meant – Kunal Vashist Sep 22 '14 at 15:31
-
I guess I don't understand what your asking by looking at your code. – brso05 Sep 22 '14 at 15:31
-
using variable i want to pass the callback function like pSr(callback) – Kunal Vashist Sep 22 '14 at 15:33
-
Your code [already seems to work](http://jsfiddle.net/fux3psd2/) but it's not at all clear what you're asking. – Pointy Sep 22 '14 at 15:34
-
possible duplicate of [Passing parameters to a JQuery function](http://stackoverflow.com/questions/370359/passing-parameters-to-a-jquery-function) – Kunal Vashist Sep 23 '14 at 07:59
1 Answers
2
I guess you want to pass along callback
to pSR
. In that case you can use .bind
:
var func = pSR.bind(null, callback);
or you put the call in another function:
rF(function() {
pSR(callback);
});
However, the choice of the parameter name is questionable, since you seem to pass a string (not a function).

Felix Kling
- 795,719
- 175
- 1,089
- 1,143