From cefa14ad99b62d1f67b2872c1a8cf05fc129fd58 Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Mon, 15 Dec 2014 22:34:10 +0800 Subject: [PATCH] Optimize: Use `new String` to avoid unnecessary string object creation --- lib/json3.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/json3.js b/lib/json3.js index b076ce4..5dfc653 100644 --- a/lib/json3.js +++ b/lib/json3.js @@ -74,7 +74,7 @@ if (name == "bug-string-char-index") { // IE <= 7 doesn't support accessing string characters using square // bracket notation. IE 8 only supports this for primitives. - isSupported = "a"[0] != "a"; + isSupported = ("a"[0] + Object("a")[0]) != "aa"; } else if (name == "json") { // Indicates whether both `JSON.stringify` and `JSON.parse` are // supported. @@ -871,7 +871,7 @@ exports.parse = function (source, callback) { var result, value; Index = 0; - Source = "" + source; + Source = new String(source); result = get(lex()); // If a JSON string contains multiple tokens, it is invalid. if (lex() != "$") {