Problem with 'this' keyword inside js file

Problem with 'this' keyword inside js file

Hello all,
I have a jquery function which loops to all my checkboxes on a grid and check or uncheck them based on the check all box.
When this function is on a javascript block inside of the page it works fine. When I move it to a .js file the 'this' keyword is 'undefined'.
here is the function
 

$('#<%=AbsentGrid.ClientID %>').find(

"input:checkbox").each(function () {

if (this != chk) {

this.checked = chk.checked;

}

});