javascript - a is a function, then what `a.call.call` really do? -
these codes run on chrome devtool.
it seems b.call(same a.call.call) calling first argument, function, pass second argument this. if first argument not function, throw not function error.
can explain how <function>.call.call work?
let me show example.
function a() { console.log(1) } function b() { console.log(2) } a.call(b) // 1 a.call.call(b) // 2 a.call.call.call(b) // 2 why?
we know a.call(b) means invoke a() this value b.
so a.call.call(b) means invoke function.prototype.call() this value b, same function.prototype.call.call(b).
but function.prototype.call.call() not ordinary function object. can invoked has no property. there's unique rules invoke it.
function.prototype.call.call(a) // 1 function.prototype.call.call(b) // 2 in fact, function.prototype.call.call(b) exotic object, furthermore, bound function exotic object.
[specification] bound function exotic object wraps function object.
[specification] calling bound function results in call of wrapped function.
so function.prototype.call.call(a) means a().
a.call.call(x) means invoke x, is, x().
- [specification] in
function.prototype.call(thisarg), if thisarg undefined or null, replaced global object.
a.call.call() means a.call.call(undefined) means a.call.call(window) means invoke window.
try invoke window you'll uncaught typeerror: window not function, try invoke a.call.call() you'll uncaught typeerror: a.call.call not function.
hope helps.

Comments
Post a Comment