Reputation: 543
the javascript code like below:
function aa(){
console.log(typeof(this))
}
console.log(typeof(aa))
aa()
the output is function and object after running this code.
so why the code output difference type?
thanks in advance!
Upvotes: 1
Views: 150
Reputation: 114569
During the execution of a function that has been called without passing a context this
is bound the the global window
object of the browser.
this
is never the function object itself, unless you pass that explicitly with call
or apply
.
The output of
function f(){console.log(typeof this);}
f.call(f);
will be function
.
Upvotes: 3