Jump to content

rclancy

Members
  • Posts

    4
  • Joined

  • Last visited

Previous Fields

  • Languages
    I used to do C/C++ and Ruby, but it's been a while.

rclancy's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. It's good to remember that 'y++' (and '++y') is shorthand for the expression 'y=y+1'. This expression contains an '=' which assigns a new value to 'y' before assigning that value to 'x'. if you want to leave 'y' unchanged try 'var x = y+1;'.
  2. Ok, this works: function useless() {return theRealFunction;}function theRealFunction() {//actual code here}window.onload = useless(); So that must be what's going on. Thanks for your help!
  3. Thanks for the reply! Let me see if I understand... The reason "window.onload = someFunction();" fails isn't a scope issue, it fails because the function is called before the document is created and then assigned to "window.onload" which then does it's thing. While "window.onload = someFunction;" doesn't execute the function, it just tells "window.onload" the name of the function to be run once the document is ready.
  4. Hey, This seems like a basic question, but I can't find any information on it. (Perhaps my google-fu is weak) When calling a function, what is the difference between "someFunction();" and "someFunction;"? It seems like they should be similar, but they are not interchangeable. Consider the following code: <!DOCTYPE html><html><head><title>Playing Around...</title><script> function theMain() { //Display the current time. function displayTime() { var elt = document.getElementById("clock"); var now = new Date(); elt.innerHTML = now.toLocaleTimeString(); setTimeout(displayTime, 1000); } //Show some info about the browser. function showInfo() { var navi = document.getElementById("navig"); navi.innerHTML = "<b>appName:</b> " + navigator.appName + "<br>" + "<b>appVersion:</b> " + navigator.appVersion + "<br>" + "<b>userAgent:</b> " + navigator.userAgent + "<br>" + "<b>platform:</b> " + navigator.platform + "<br>" + "<b>onLine:</b> " + navigator.onLine + "<br>" + "<b>geolocation:</b> " + navigator.geolocation; return; } //console.log("theMain"); showInfo(); displayTime(); } window.onload = theMain; </script><style> #clock { font: bold 24pt sans; background: #ddf; padding: 10px; border: solid black 2px; border-radius: 10px; } #navig { font: 12pt sans; background: #ddf; padding: 10px; border: solid black 2px; border-radius: 10px;</style></head><body><h1>Clock</h1><span id="clock"></span><h2>Navigator Information</h2><div id="navig"></div></body></html> There are three functions, and if the outer function is called like "window.onload = theMain;" everything is cool, but if we call it like "window.onload = theMain();" The inner functions fail with and uncaught type error ("can't set innerHTML of null.") Similarly, if the inner functions are called without without parentheses, they fail to execute. I'm sure this is a scope issue, but for the life of me, I can't figure it out. Can anyone shed some light on this? Thanks!
×
×
  • Create New...