I found interesting output when I set this
to a string using apply
and then console.log
'd it. What's up?
In Chrome's Javascript console,
(function(){ return this }).apply("hello");
Outputs to:
String {0: "h", 1: "e", 2: "l", 3: "l", 4: "o"}
Why isn't it "hello"
like I would have expected?
Interestingly, checking this output with typeof
:
typeof (function(){ return this }).apply("hello");
Gives me "object"
, instead of "string"
.
I'm guessing that is some wizardry with apply
that I don't understand?