1. #1
    Sencha User
    Join Date
    May 2011
    Location
    Atlanta, GA
    Posts
    9
    Vote Rating
    0
    xiinteractive is on a distinguished road

      0  

    Default listeners event syntax - to single quote or not

    listeners event syntax - to single quote or not


    I have noticed that ExtJs 4.x docs do not show single quotes around events in the listeners.
    In ExtJs 3.x some examples show this and some do not.
    We found that our results were more consistent in ExtJs 3.x when we single-quoted the listener events.

    That said, is there an impact in ExtJs 4.x for using single quotes on the listener events?
    Has this been fixed in ExtJs 4.x?

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,509
    Vote Rating
    288
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Could you give an example of what you've described?

  3. #3
    Sencha User matei's Avatar
    Join Date
    Jun 2008
    Location
    Cluj-Napoca
    Posts
    28
    Vote Rating
    0
    matei is on a distinguished road

      0  

    Default


    In documentation for ext 3 we can see an example:
    http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.util.Observable-method-addListener

    Code:
    myGridPanel.on({
        'click' : this.onClick,
        'mouseover' : this.onMouseOver,
        'mouseout' : this.onMouseOut,
        scope: this
    });
    while in ext 4 same example does not have quotes:
    http://docs.sencha.com/extjs/4.2.2/#...od-addListener

    Code:
    myGridPanel.on({
        cellClick: this.onCellClick,
        mouseover: this.onMouseOver,
        mouseout: this.onMouseOut,
        scope: this // Important. Ensure "this" is correct during handler execution
    });
    There is no diference if you use or not quotes if your events are single words (that don't contain spaces or other special chars), because it is a simple json object that is passed to on/addListener function. So any valid json is ok, and the only difference I can see is size (2 more chars for each event).
    In this case I'll prefer to write without any quotes.

    Also if you run following code you'll get that each element from an json when is iterated is converted to string:

    Code:
    var options = {
        event1: function(){},
        'event2': function(){}
    };
    for(obj in options){
        console.debug(obj, '-', (typeof obj));
    }

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,664
    Vote Rating
    584
    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


    The short answer is there's no difference whether you quote property names or not. Unless you've got an event name you can't use as a key:

    Code:
    {
        my-event: fn // fails
        'my-event': fn // all good
    }
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!