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
Post a Comment