This line from your fiddle:
window.onresize = gridfill.layoutGrid();
...doesn't assign your function as a resize handler, it calls your function immediately and tries to assign the return value as a resize handler. You need to remove the parentheses:
window.onresize = gridfill.layoutGrid;
Except to keep the correct context within the function you will need to use:
window.onresize = gridfill.layoutGrid.bind(gridfill);
Note that the .bind()
function is not supported by IE<=8, but you can use a polyfill, or just wrap the function call:
window.onresize = function() { gridfill.layoutGrid(); };