You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@royale.apache.org by GitBox <gi...@apache.org> on 2019/07/07 19:01:18 UTC

[GitHub] [royale-compiler] Harbs opened a new issue #90: Bad "this"

Harbs opened a new issue #90: Bad "this"
URL: https://github.com/apache/royale-compiler/issues/90
 
 
   I have a class which has the following function:
   ````
       private function loadApi(endpoint:String):void{
         var request:URLRequest = RequestUtil.getRequest(endpoint);
         loader.onComplete = function (l:URLBinaryLoader):void
         {
           status = "complete";
           if(canceled){
             return;
           }
           var stringRes:String = l.data.readUTFBytes(l.data.length);
           if(stringRes){
             result = JSON.parse(stringRes);
           }
           complete(this);
         }
         loader.onError = function (l:URLBinaryLoader):void
         {
           status = "error";
           if(canceled){
             return;
           }
           var stringRes:String = l.data.readUTFBytes(l.data.length);
           result = JSON.parse(stringRes);
           error(this);
         }
         request.data = params;
         loader.load(request);
       }
   ````
   It compiles to:
   ````
   com.printui.services.APIService.prototype.com_printui_services_APIService_loadApi = function(endpoint) {
     var self = this;
     var /** @type {org.apache.royale.net.URLRequest} */ request = com.printui.utils.RequestUtil.getRequest(endpoint);
     this.loader.onComplete = function(l) {
       self.status = "complete";
       if (self.canceled) {
         return;
       }
       var /** @type {string} */ stringRes = l.data.readUTFBytes((l.data.length) >>> 0);
       if (stringRes) {
         self.result = JSON.parse(stringRes);
       }
       self.complete(this);
     };
     this.loader.onError = function(l) {
       self.status = "error";
       if (self.canceled) {
         return;
       }
       var /** @type {string} */ stringRes = l.data.readUTFBytes((l.data.length) >>> 0);
       self.result = JSON.parse(stringRes);
       self.error(this);
     };
     request.data = this.com_printui_services_APIService_params;
     this.loader.load(request);
   };
   ````
   `self.complete(this);` and `self.error(this);` are both pointing to the wrong `this`.
   
   The code should be output as `self.complete(self);` and `self.error(self);`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services