In following code I am not able to understand why the value of this changes to window from document in function handler when I call it from the document context.
$(document).ready(function() {
var handler = function() {
console.log(this); // this = window
}
console.log(this); // this = document
handler();
})
As per my understanding the value of this is determined from its execution context. Now when I am document.ready function this points to document which is expected, but when I call method from that context, why is my context changing to window from document.
Thanks in advance.