From 778e6cef1b2ea827b31136a39ad4d91c6af6fd94 Mon Sep 17 00:00:00 2001 From: Will Date: Mon, 11 Sep 2017 18:07:15 +0800 Subject: [PATCH] Update toString.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit option中包含多个function的情况 --- src/util/toString.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util/toString.js b/src/util/toString.js index ac379ba..b4a6904 100644 --- a/src/util/toString.js +++ b/src/util/toString.js @@ -1,8 +1,13 @@ export default function toString(obj) { - return JSON.stringify(obj, function(key, val) { - if (typeof val === 'function') { - return `~--demo--~${val}~--demo--~`; - } - return val; - }).replace('\"~--demo--~', '').replace('~--demo--~\"', '').replace(/\\n/g, ''); + let result = JSON.stringify(obj, function(key, val) { + if (typeof val === 'function') { + return `~--demo--~${val}~--demo--~`; + } + return val; + }); + + do { + result = result.replace('\"~--demo--~', '').replace('~--demo--~\"', '').replace(/\\n/g, '').replace(/\\\"/g,"\"");//最后一个replace将release模式中莫名生成的\"转换成" + } while (result.indexOf('~--demo--~') >= 0); + return result; }