Hybrid View

    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
    Join Date
    Jul 2008
    Location
    New Zealand
    Posts
    91
    Vote Rating
    3
    Greendrake is on a distinguished road

      0  

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

    [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
    16,947
    Vote Rating
    636
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      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
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    St Louis,MO
    Posts
    267
    Vote Rating
    18
    James Goddard will become famous soon enough James Goddard will become famous soon enough

      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
    N├╝rnberg, Germany
    Posts
    78
    Vote Rating
    29
    harrydeluxe has a spectacular aura about harrydeluxe has a spectacular aura about

      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
    16,947
    Vote Rating
    636
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      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
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  6. #6
    Sencha User
    Join Date
    Aug 2009
    Posts
    7
    Vote Rating
    2
    brianpolk is on a distinguished road

      0  

    Default


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