javascript - How Do You Know How To Initialize A Script? -
javascript - How Do You Know How To Initialize A Script? -
2 questions:
1) how know how initialize script? code in spot in js file, have create initializing code scratch, etc?
2) why don't have "activate"/initialize jquery script? other scripts i'm using required activating, why jquery.js doesn't require internal script going?
just trying wrap head around concept, in advance!
in web page, javascript loaded , executed via html tags of:
<script src="scriptfile"></script>
or inline with
<script> ... code here ... </script>
in both/either cases, javascript loaded/found executed top of source way bottom in order found.
there no "initialization" of javascript might found in, say, java or c. there no equivalent of main() function in:
class x { public static main(string args[]) { .... } }
in javascript code starts "executing" top.
it not uncommon see javascript code begin wait dom loaded , prepared. illustration script starts:
$(function() { // ... code here ... });
should read execute function called "$" , pass annonymous function should run when dom has loaded. these symbols, curly braces, brackets , such can confusing best way comprehend them still realize code runs top bottom ... may not run immediately. example:
var x = function() { // ... code ... }; x();
even though there may tons of code within function definition, not run until phone call function made. in javascript separate code definitions code execution.
see related q&a:
main() function in javascript?
javascript jquery initialization
Comments
Post a Comment