how would you write a independant JS library(no jquery), that u could just use to check if the document is ready

how would you write a independant JS library(no jquery), that u could just use to check if the document is ready

hey guys , i got a bit of a twisted question , i always wonder how exactly does 

  1. $(function(){

  2. });

work similar to 

  1. $(document).ready(function(){

  2. });
i looked at the source and i see the below code :: 

  1. else if (jQuery.isFunction(selector)) {
  2.         return typeof rootjQuery.ready !== "undefined" ? rootjQuery.ready(selector) :
  3.         // Execute immediately if ready is not present
  4.         selector(jQuery);
  5.     }
which is somewhat difficult to understand  how does 

  1. $(function(){})
work behind the scenes. 

if you had to a function that that checks if the document is ready and more importantly can be called using the same syntax as above , how would you code that part ? 

can somebody show me a example ? psedo code will do :D 

i know its a bit of a stu pid question , but i would appreciate any insight . 

Thank you. 

Gautam.