What you are looking for is Differences between document.ready and $function
They both are same
(function($){
})(jQuery);
or
$(document).ready(function(){
});
although the code you have provided should work but what you need to do is either use
(function($){
alert( $(window).width() );
alert(1);
})(jQuery);
or
$(document).ready(function(){
alert( $(window).width() );
alert(1);
});
Update
Also take a look at $.ready
documentation http://api.jquery.com/ready/