1. #1
    Sencha User conorarmstrong's Avatar
    Join Date
    Mar 2008
    Location
    Northern Ireland
    Posts
    224
    Vote Rating
    2
    conorarmstrong is on a distinguished road

      0  

    Default scope used for Ext.decode (Ext.util.JSON.decode)

    scope used for Ext.decode (Ext.util.JSON.decode)


    I've a JSON string needing decoded - say for example

    Code:
    this.b=100;
    var json='{a: this.b}';
    var obj=Ext.decode(json);
    console.log(obj.a); // undefined
    The usual Ext.decode() function doesn't inherit the scope of the caller and doesn't allow passing a variable which allows the scope to be specified when decoding the JSON string - eg Ext.decode(json, this);

    I've been able to use the javascript call method to execute the Ext.decode() within the scope of this as follows:

    Code:
    this.b=100;
    var json='{a: this.b}';
    var obj=Ext.decode.call(this,json);
    console.log(obj.a); // works
    I've had a look at the underlying code of Ext.decode() If the native JSON.parse is available it uses that, otherwise it uses eval() to do the parsing. In my case (Firefox 3.0.10 eval is used)

    Does anyone know what scope JSON.parse uses by default if native support exists for it? Would a call method be needed to specify a particular scope?

    Also, would it be an idea to modify the implementation of Ext.decode() to allow the passing of scope?
    ------------------------------------------
    Conor Armstrong
    tw: @evathedog
    web: rockstown.com

    Ext.ux.form.AutoCombo
    Ext.ux.SimpleIFrame
    Ext.ux.form.ToolFieldSet

    Knowledge is realising that the street is one-way, wisdom is looking both directions anyway.

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,483
    Vote Rating
    35
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    JSON does not have a scope. It is just on object literal containing defined properties. What you have there is not valid JSON.

    http://json.org/

  3. #3
    Sencha User conorarmstrong's Avatar
    Join Date
    Mar 2008
    Location
    Northern Ireland
    Posts
    224
    Vote Rating
    2
    conorarmstrong is on a distinguished road

      0  

    Default


    Thanks, that explains a lot!

    ------------------------------------------
    Conor Armstrong
    tw: @evathedog
    web: rockstown.com

    Ext.ux.form.AutoCombo
    Ext.ux.SimpleIFrame
    Ext.ux.form.ToolFieldSet

    Knowledge is realising that the street is one-way, wisdom is looking both directions anyway.

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar