Function myFunction (test1, test2 ){
// Parameters passed in with apply must be explicitly declared and retrieved in the put order
// Alert (extendStr );
Alert (test1 );
Alert (test2 );
// After binding the property, you can call the function without passing in it, but you cannot use this
Alert ("myFunction. extendStr =" + myFunction. extendStr );
}
Function extendFunction (callbackFunction, extend ){
Var extendStr = "this is extend string! ";
Var args = [];
If (typeof (extend) = "object "){
For (var property in extend ){
// Bind property, which can be called by the function itself
CallbackFunction [property] = extend [property];
// Put the parameter values in the array in order and pass the values through apply
Args. push (extend [property]);
}
}
// Bind property, which can be called by the function itself
CallbackFunction ["extendStr"] = extendStr;
// Put the parameter values in the array in order and pass the values through apply
Args. push (extendStr );
// Call the function dynamically and input the parameter value Array
Alert ('C ');
CallbackFunction. apply (this, args );
}
// Dynamically extend and execute the function, which is generally used for processing ajax callback functions.
ExtendFunction (myFunction, {test1: 'aaa', test2: 'bbb '});