Results 1 to 10 of 10

Thread: [4.1-20120123] Unable to use 'class' model fields

Hybrid View

Previous Post Previous Post   Next Post Next Post
    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-5217 in a recent build.
  1. #1
    Ext JS Premium Member Greendrake's Avatar
    Join Date
    Jul 2008
    Location
    New Zealand
    Posts
    199
    Vote Rating
    34
      0  

    Default [4.1-20120123] Unable to use 'class' model fields

    It's pretty understandable that the word class is a reserved word in JavaScript and so it's not a good idea to use that word as a name of variable. As for keys/identifiers (such as model/record field names), it has never been a problem. Until ExtJS 4.1.
    So, the following code
    Code:
    Ext.define('Foo', {
        extend: 'Ext.data.Model',
        fields: ['class']
    });
    generates a "class is a reserved identifier" error on Firefox 9.0.1):

    class-ext4.1.png

    For some reason, field identifiers get evaluated to variables.
    So, the question is: do I have to go through my code and replace all "class" fields with "cls", or is this behaviour unintentional and will be fixed?

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,590
    Vote Rating
    873
      0  

    Default

    This was an unintentional regression, it will be fixed in B3.

    To fix it, in Reader.js:

    Code:
    // current
    fieldVarName[i] = Ext.String.createVarName(field.name);
    
    // fix
    fieldVarName[i] = '_' + Ext.String.createVarName(field.name);
    Evan Trimboli
    Twitter - @evantrimboli

  3. #3
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    St Louis,MO
    Posts
    267
    Vote Rating
    18
      0  

    Default

    Just want to link back to http://www.sencha.com/forum/showthre...031#post722031.

    It's a bit different. In this case the field name is a reserved word in javascript, in the other case the field name matches a local parameter.

    As you said in the other thread, the same fix will likely take care of both but a linkback is a good idea so we make sure .

    James

  4. #4
    Sencha Premium Member harrydeluxe's Avatar
    Join Date
    Jul 2007
    Location
    Nrnberg, Germany
    Posts
    78
    Vote Rating
    33
      0  

    Default

    The same with "default".
    DELACAP | Github
    "don't code today what you can't debug tomorrow"

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,590
    Vote Rating
    873
      0  

    Default

    Just for the sake of completeness, there are 3 types that will fail at the moment:

    1) Reserved words
    2) Names that conflict with the local vars in the function
    3) Names that start with numbers

    A fix that addresses these cases has been pushed up to the main repo and is awaiting a merge.
    Evan Trimboli
    Twitter - @evantrimboli

  6. #6
    Sencha User
    Join Date
    Aug 2009
    Posts
    7
    Vote Rating
    2
      0  

    Default

    It seems that you can add one more illegal word for field names: "source"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •