javascript - Assign a function with custom parameters without calling the funcion -
I have a function that accepts other functions in run-time as B parameter and calls it problem Function B requires some parameters, but with the function A to the parameter, how to pass the function A, I do not know.
Example:
function caller function (c) {warnings ("caller function is calling!"); C (c.arguments); }; Var a = "Hello"; Do it (d) {d = "I changed my way"; Warning (d); }; Caller function (/ * I need to pass' this' with parameter / variable 'A', and then call it in callerfunction '* / /);
Just close a closing:
callerfunction (Function () {thisOne (a);}); and call it as c () , no c (c.arguments) . Note that in this anonymous function the reference to the a variable will not be there, the value will be a so if callerFunction () Had to store this function object and call it later, if you have an anonymous function passing and it is called, then a from the perspective of anonymous function a would have changed: var a = 1; Var fn = function () {console.log (a); }; Fn (); // log1a = 2; Fn (); // log2
Comments
Post a Comment