Are those two codes trying to solve the same problem? the context of
this?
Yes, but in a different manner.
The first version invokes Function.prototype.call
which as first argument, accepts the context-object to which the this
variable within the called function-context will refer to.
The second version just self-invokes the anonymous function and passes the object which refers to this
(in the calling context) to the anonymous function. Now, within the called anonymous function-context, we can access it via that
. this
will be global
or undefined
(depends on ES5 strict mode)
0
Created by jAndy on 2020-03-18 04:47:21 +0000 UTC
Share