code_junkie

Beginner: Javascript must be on header to run? Does the declaration order of the functions matter?

Nov 12th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <head>
  2. window.onload = function(){
  3. var x = new Array(0,2,3,4,5,6,7,8);
  4. var y = new Array(20,10,40,30,60,50,70,10);
  5. drawGraph(y,x);
  6. }
  7. </head>
  8.  
  9. function addLoadEvent(func) {
  10. var oldonload = window.onload;
  11. if (typeof window.onload != 'function') {
  12. window.onload = func;
  13. }
  14. else {
  15. window.onload = function() {
  16. oldonload();
  17.  
  18. var x = new Array(0,2,3,4,5,6,7,8);
  19. var y = new Array(20,10,40,30,60,50,70,10);
  20. drawGraph(y,x);
  21. }
  22. }
  23. }
  24.  
  25. $(document).ready(function() {
  26. var x = new Array(0,2,3,4,5,6,7,8);
  27. var y = new Array(20,10,40,30,60,50,70,10);
  28. drawGraph(y,x);
  29. })
  30.  
  31. <html>
  32. <head>
  33. <script type="text/javascript">
  34. function check_existance()
  35. {
  36. if(!check_existance.i)
  37. check_existance.i = 0;
  38.  
  39. document.write("<h5>Call : " + ++check_existance.i + "</h5>" +
  40. "func1 : " + typeof func1 + "<br />" +
  41. "func2 : " + typeof func2 + "<br />" +
  42. "func3 : " + typeof func3 + "<br />" +
  43. "func4 : " + typeof func4 + "<br />");
  44. }
  45. </script>
  46. <script type="text/javascript">
  47. check_existance();
  48.  
  49. func1 = function()
  50. {
  51. alert("func1");
  52. };
  53.  
  54. check_existance();
  55.  
  56. function func2()
  57. {
  58. alert("func2");
  59. }
  60. </script>
  61. </head>
  62. <body>
  63. <script type="text/javascript">
  64. check_existance();
  65.  
  66. func3 = function()
  67. {
  68. alert("func3");
  69. };
  70.  
  71. check_existance();
  72.  
  73. function func4()
  74. {
  75. alert("func4");
  76. }
  77. </script>
  78. </body>
  79. </html>
Add Comment
Please, Sign In to add comment