Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6202] MobileWeb: Creating new classes without a definition throws error when instantiating

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2012-01-16T12:06:43.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sn/a
ComponentsMobileWeb
Labelsstage
ReporterChris Barber
AssigneeChris Barber
Created2011-11-16T09:54:09.000+0000
Updated2014-01-28T23:57:35.000+0000

Description

In Ti._5.createClass(), if the class definition (value) is not a function, it defaults the definition to "new Object()". This works fine, however if you try to create a new instance of this class, it throws a JavaScript error.

Comments

  1. Chris Barber 2011-11-16

    Turns out there is inconsistent use of createClass(). Sometimes it's used to create an instantiable object with the "new" operator such as when:
       Ti._5.createClass('Titanium.UI.Button', function(){ ... });
       
       var button = new Titanium.UI.Button();
       
    There are other times when createClass() is used to create a non-instantiable object that fails if you do a "new" operator:
       Ti._5.createClass('Titanium.API');
       
       var api = Titanium.API;
       api.something = true;
       
       var foo = new Titanium.API(); // throws error
       
    Probably best to solve this by creating a new method called createObject() to explicitly differentiate between objects and classes:
       Ti._5.createObject('Titanium.API');
       
  2. Chris Barber 2011-11-16

    Bryan and I discussed and we agree this should be separated. Start by renaming createClass() to declare(). As for createObject(), perhaps something like getObject() or object() or obj()?
  3. Bryan Hughes 2011-11-16

    I don't have a strong preference, but I think I am leaning towards object(). Aesthetically it seems to compliment declare() the best.
  4. Chris Barber 2012-01-16

    This entire issue has been eliminated since rolling out the new class hierarchy in TIMOB-6772.

JSON Source