Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13289] CodeProcessor: The this value for callbacks is incorrect

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2013-04-01T17:12:27.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.1.0, 2013 Sprint 07 JS, 2013 Sprint 07
ComponentsCode Processor
Labelsn/a
ReporterBryan Hughes
AssigneePraveen Innamuri
Created2013-04-01T17:09:14.000+0000
Updated2017-03-16T20:57:41.000+0000

Description

The this value for callbacks (e.g. in addEventListener) are currently set to global scope, but should be set to the object the callback was added to.

Comments

  1. Eric Merriman 2013-06-17

    Please provide test steps and sample code.
  2. Bryan Hughes 2013-06-17

    Run the following sample code from the command line (cannot run from studio) using "ti analyze -p iphone -A":
       var win = Ti.UI.createWindow({
           backgroundColor: 'red'
       });
       
       win.addEventListener('click', function () {
           console.log(this.backgroundColor);
       });
       
    Sift through the output to find a line that starts with "[INFO] program output [log]:". Without the fix, it will say "[INFO] program output [log]: undefined" but with the fix it will say "[INFO] program output [log]: red".
  3. Lee Morris 2017-03-16

    Closing ticket as fixed.

JSON Source