DOM onLoad event without jquery -


html code :

<html>    <head>    </head>    <body>       <script type="text/javascript" src="/js/colorbook.js"></script>       <script type="text/javascript">           book.init();       </script>    </body> </html> 

js code :

var book = (function(){    init = function(){    console.log ( "initialized")    }return init(); }()); 

question : above code works. unable understand how?. can of js guys me here or guide me how should start debug code understand it.

ok per comment. javascript have there executed sequentially browser reads incoming data stream. being said, javascript contained within first script tag executed. second script tag executed in sequence well.

so right can @ book.init() being last provided javascript call executed.

i tried js code in jsfiddle , not work check this fiddle see mean.

what happening in js code last () @ end of var book declaration executes anonymous function print line console. code supplied book variable never gets book.init() method. once call reached throw error of undefined.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -