-
1 Jun 2009 12:00 PM #1
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
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);Code:this.b=100; var json='{a: this.b}'; var obj=Ext.decode(json); console.log(obj.a); // undefined
I've been able to use the javascript call method to execute the Ext.decode() within the scope of this as follows:
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)Code:this.b=100; var json='{a: this.b}'; var obj=Ext.decode.call(this,json); console.log(obj.a); // works
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.
-
1 Jun 2009 12:05 PM #2
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/Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
1 Jun 2009 12:29 PM #3
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.


Reply With Quote