Let's start with a simple topic that we saw on git a few days ago:
Defines the log method, which can proxy console.log methods.
Log (1 2 3)
Usually, your answer will be this:
function log () { var args = Array.prototype.slice.call (arguments); Console.log.apply (console, args); };
Until one day, you see a very tall on the answer:
function log () { Function.prototype.apply.call (console.log,console, arguments);};
Function.prototype.apply.call .... What the hell is this???
Well, then you must know Function.prototype.apply, and we'll cache it:
var core_apply=function.prototype.apply;
Core_apply.call (console.log,console, arguments) we can break it down
1, call core_apply method, Console.log is core_apply This method of this point, console,arguments is to pass to core_apply this method parameter.
In other words, it is actually equivalent to
Console.log.core_aply (console,arguments);
=
Call the Console.log () method, this points to the console, and the passed-in parameter is arguments.
Function.prototype.apply.call