Reply to topic
Javascript question
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 343
Reply with quote
I just don't get this... This works:
Code:
   var Terra = {
      setlink: function(e) {
         document.getElementById(e).setAttribute("class", "selectedLink");
      }
   }   

And this works also:
Code:
      var Terra = { logout: function() {
         alert("You have been logged out.");
         // XMLHTTTP to logout
      }
}

Yet when I try this by combining the two subvariables:
Code:
      var Terra = {
      setlink: function(e) {
         document.getElementById(e).setAttribute("class", "selectedLink");
      } logout: function() {
         alert("You have been logged out.");
         // XMLHTTTP to logout
      }
   }   
, It doesn't work... I get the error
missing } after property list
TMPcfixgb53pz.htm (line 7Cool
logout: function() {
What's wrong with my code? Thanks for your help and time.
pmeserve
HostMySite Tech

Joined: 19 Mar 2004
Posts: 178
Reply with quote
Note sure if this is relevant, I'm not very good with Javascript. This code I threw together seems similar in principle though, and does work:

Code:
<script>
function run_twice(func) {
   for(var $i=0; $i < 2; $i++)
           func($i);
}

run_twice(function(c) {
        // test
        c2 = 1;
        alert("test " + c + "." + c2);
        alert("test " + c + "." + ++c2);
        alert("test " + c + "." + ++c2);
})

run_twice(alert("test"));
</script>
Class oriented Programming
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 343
Reply with quote
That code probably should work, although maybe I am trying to be too perfectionist - Having a variable with multiple subfunctions, as if it were a class probably isn't worth all this extra debugging. Thanks for your help and time.

BTW: This is why I use Prototype and RJS for most of my Javascript
Javascript question
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic