0

I'd like to store multiple functions in one object. However, my current code seems to overwrite the previous data.

Related: https://stackoverflow.com/a/3733591/309535

Because it is a loop with other stuff going on, the code cannot be within the same block of javascript.

My Code:

<script type="text/javascript">
var at = {
  atleft_1: function drawChart() {
    // data goes here
  }
 }
 </script>

// Next loop

<script type="text/javascript">
var at = {
  atleft_2: function drawChart() {
    // data goes here
  }
 }
 </script>
Community
  • 1
  • 1
brant
  • 537
  • 3
  • 7
  • 17

2 Answers2

4

If at is already defined, just assign a property:

var at = {};
at.atleft_1 = function.....;
at.atleft_2 = function.....;

Although by the look of it you may be better of with:

at.atleft = function(id) {...};
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

You Can do something like this:

<script type="text/javascript">
var at = {
     atleft_2: function() {
         // data goes here
    },
    atleft_1: function(){
       //data goes here
   }
};
</script>

Why are you using drawChart?? I didn't get it.

emphaticsunshine
  • 3,725
  • 5
  • 32
  • 42
  • Drawchart is from Google Charts. Adding multiple graphs to one page. This was the best method I could figure out. . . http://code.google.com/apis/chart/interactive/docs/gallery/linechart.html – brant Feb 03 '12 at 18:58
  • so you should call that function with those functions. – emphaticsunshine Feb 03 '12 at 19:31