What are some common ways to call a JavaScript function?

  1. Call the function directly and pass in the parameters.
function functionName(param1, param2) {
  // 函数体
}

functionName(value1, value2);
  1. Invoke a function with parameters using the call() method.
function functionName(param1, param2) {
  // 函数体
}

functionName.call(null, value1, value2);
  1. Call the function with the apply() method and pass in the arguments:
function functionName(param1, param2) {
  // 函数体
}

functionName.apply(null, [value1, value2]);
  1. Create a new function using the bind() method and pass in arguments.
function functionName(param1, param2) {
  // 函数体
}

var newFunction = functionName.bind(null, value1, value2);
newFunction();
  1. Passing as a callback function into another function.
function functionName(param1, param2) {
  // 函数体
}

function callbackFunction(callback) {
  callback(value1, value2);
}

callbackFunction(functionName);
bannerAds