http://jsfiddle.net/raylu/C6Tkn/
function a() {
document.write(this + '<br />');
}
a();
a.apply('hello');
var b = function() {
a();
}
b.apply('hi');
I would expect the last line to output ‘hi’, but instead it outputs window.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
thisis meant to bewindowin that context.b()‘sthisis'hi', but that isn’t inherited/associated with any function calls in the body of theb()function. That is whythisinside ofa()when called viab()with the normal function invocation method (()) iswindow.