-
11 Nov 2009 9:06 AM #1
Unanswered: 183 bytes can be saved in JSON.js
Unanswered: 183 bytes can be saved in JSON.js
I provided a patch for saving 183 bytes in JSON.js here: http://www.extjs.com/forum/showthrea...375#post352375
However, nobody noticed because I posted after the thread had been marked as FIXED. Mystix recommended that I start a new thread, so that's what I'm doing now
.
Best regards,
PapandreouLast edited by papandreou; 11 Nov 2009 at 11:09 AM. Reason: typo
-
11 Nov 2009 9:30 AM #2Sencha - Services Team
- Join Date
- Aug 2007
- Location
- Long Island, NY USA
- Posts
- 5,956
- Vote Rating
- 8
- Answers
- 9
How about we actually implement the 'safe' option, too ?

As proposed:
or, as the current closure [SVN]:Code:/** * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError unless the safe option is set. * @param {String} json The JSON string * @return {Object} The resulting object */ this.decode = function(o) { var decoder = Ext.USE_NATIVE_JSON && nativeJSONAvailable ? JSON.parse : doDecode; if(!!safe){ var obj = null; try{ obj = decoder(json); } catch(je){} finally { return obj; } }else { return decoder(json); } }; }()
Code:/** * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError unless the safe option is set. * @param {String} json The JSON string * @return {Object} The resulting object */ this.decode = function() { var dc; return function(json, safe) { if (!dc) { // setup decoding function on first access dc = isNative() ? JSON.parse : doDecode; } if(!!safe){ var obj = null; try{ obj = dc(json); } catch(je){} finally { return obj; } }else { return dc(json); } }; }()"be dom-ready..."
Doug Hendricks
Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.
Got Sencha licensing questions? Find out more here.
-
11 Nov 2009 11:20 AM #3
Seems like a topic for a separate thread

If your patch is accepted, I propose that we save another two bytes by omitting the two nots. Semantically the above code is exactly identical to if(safe) {... I realize why you'd sometimes want to use that trick to force a value to be converted to boolean, but here you're just asking about the truth value.Code:if(!!safe){
Best regards,
Papandreou
-
11 Nov 2009 11:24 AM #4Sencha - Services Team
- Join Date
- Aug 2007
- Location
- Long Island, NY USA
- Posts
- 5,956
- Vote Rating
- 8
- Answers
- 9
Agreed, dbl-negation optional.
"be dom-ready..."
Doug Hendricks
Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.
Got Sencha licensing questions? Find out more here.
-
18 Nov 2009 3:27 PM #5
how can
be different fromCode:if(!!safe)
?Code:if (safe)
I think the boolean cast will happen anyhow? No?


Reply With Quote


