title: odd value of "this" in javascript
body: <p>In the code below this gets as value [function()] according to firebug, instead of the object returned by the define. </p>
  
  <hr>
  
  <pre><code>define(["dojo/dom", 
          "dojo/dom-construct", 
                  ......., 
          "dojo/domReady!"], 
  
  function(dom, 
           construct, 
           ........){ 
  
      return { 
  
          is_empty_attr: function(attr){ 
              if (attr.many){ 
                  return attr.peeks.length === 0; 
              } else { 
                  return !attr.peeks; 
              } 
          }, 
                  ................ 
  
          add_button: function(attr){ 
              console.log(this); &lt;- 1
              var self = this; 
              return new Button({ 
                  label: 'add', 
                  showLabel: false, 
                  iconClass: "add_icon", 
                  disabled: this.is_empty_attr(attr), &lt;- 2
                  onClick: function(){ 
                      if (attr.inline){ 
                          ajax.newObject(self.sub_path_func(attr), function(json){ 
                              self.object_table(json, "val_"+attr.path); 
                          }); 
                      } else { 
                          ajax.newObject(self.sub_path_func(attr), function(json){ 
                              self.object_dialog(json); 
                          }); 
                      } 
                  } 
              }); 
          }, 
  
      };     
  }); 
  </code></pre>
  
  <hr>
  
  <p>line (&lt;-1) logs "[function()]" 
  line (&lt;-2) therefore gives an undefined function error. </p>
  
  <p>Does anyone have any idea why this happens and how to fix it?</p>
  
  <p>[edit] I've solved the problem (by guesswork), but in the original version i passed the array [this.add_button, this.someotherbutton] to another function which called each function in the array with the attr argument. All methods are part of the same returned object of the dojo define method. It worked after i passed [this.add_button(attr), this.someotherbutton(attr)] (so the actual buttons) as argument to the second function.</p>
  
  <p>I still don't understand how that changed the "this" value in add_button, since both methods where add_button was called seem comparable, so if someone could explain i would be grateful.[end edit]</p>
  
  <p>Cheers, Lars </p>