Kunal Vashist
Kunal Vashist

Reputation: 2471

How to pass method parameter?

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");
});

Upvotes: 0

Views: 102

Answers (1)

Felix Kling
Felix Kling

Reputation: 816324

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).

Upvotes: 2

Related Questions