?
console.log console this ,
pseudo-array arguments .
, arguments "hi", "there" , , :
console.log("hi", "there");
?
, ?
apply call:
this . apply
( ). call .
apply call, :
someFunction.apply(valueForThis, ["arg1", "arg2", "arg3"]);
// or
someFunction.call(valueForThis, "arg1", "arg2", "arg3");
apply call , (apply= in
- , call= ).
, ?
console.log.apply(console, arguments);
: console.log - , . , JavaScript
apply.
, console.log, apply.
Function.prototype. , JavaScript.
- , apply call JavaScript.
, , console.log (, Function.prototype), apply .
, call apply apply console.log.
Can more applications be simplified to achieve the same result?
Not very, not so much that we can share. I will try to use variable names to clarify:
var thisValue = console;
var functionToCall = console.log;
var applyFunction = Function.prototype.apply;
applyFunction.call(functionToCall, thisValue, arguments);