Loading ...
Sorry, an error occurred while loading the content.

Re: YAHOO.util.Event.addListener breaking object properties

Expand Messages
  • tssha
    ... The scope of this in update() is window instead of av(the DDPortal object). Correcting the scope to av will output updating: 1,2,3 ... instead of
    Message 1 of 2 , Feb 1, 2007
    • 0 Attachment
      --- In ydn-javascript@yahoogroups.com, "visseraj" <visseraj@...> wrote:
      >
      > If I use the YAHOO.util.Event.addListener to load an object instead of
      > using the body onload method, the properties of my object are undefined.
      > See the code below for a better explanation
      >
      > function DDPortal() {
      > this.columns = new Array();
      > this.columns.push(1,2,3);
      > this.widgets = new Array(new Array(),new Array(),new
      > Array());
      > this.update = update;
      > }
      >
      > function update() {
      > console.log('updating: ' + this.columns);
      > console.log('updating: ' + this.widgets);
      > }
      >
      > av = new DDPortal;
      > //YAHOO.util.Event.addListener(window, "load", av.update);
      > </script>
      >
      > </head>
      > <body onload="av.update();">
      >
      >
      > The code as it stands will output:
      > updating: 1,2,3updating: ,,
      >
      > but if I uncomment the addListener line and remove the body onload I
      > get:
      > updating: undefinedupdating: undefined

      The scope of "this" in update() is window instead of av(the DDPortal
      object). Correcting the scope to av will output "updating: 1,2,3"...
      instead of undefined.

      Regards,
      Thomas
    Your message has been successfully submitted and would be delivered to recipients shortly.