$(function(){
var $window = $(window),
$header = $('.header'),
$this = $(this); // <-----here you can cache your selectors
$window.on('scroll', function(){
if($this.scrollTop() > 0){
$header.addClass('shadow');
}else{
$header.removeClass('shadow');
}
}).scroll();
});