Design & Download
Your JS Library
in Seconds!!!

Snippet: callReturn() - Call & Return A Function

Written by Christopher West (cwest) on March 12, 2016.
Calls a function and then returns the function that was called.
function callReturn(fn) {
  fn.apply(this, slice(arguments, 1));
  return fn;
}

callReturn() API Documentation

Calls a function and then return the function that was called.

Parameters

  1. fn {Function}:
    The function to be called and returned. The return value of this function will be ignored.
  2. ...args {*}:
    Every argument that is passed after fn will be passed as an argument to fn when it is called.

Returns

Returns fn.

When Useful

  1. When you need to call a function that is also being bound to an event.
  2. When you need to call a function that is also being assigned to a variable and you want the function name to persist.