Update toString.js

option中包含多个function的情况
This commit is contained in:
Will 2017-09-11 18:07:15 +08:00 committed by GitHub
parent 9fc5b29aec
commit 778e6cef1b
1 changed files with 11 additions and 6 deletions

View File

@ -1,8 +1,13 @@
export default function toString(obj) {
return JSON.stringify(obj, function(key, val) {
let result = JSON.stringify(obj, function(key, val) {
if (typeof val === 'function') {
return `~--demo--~${val}~--demo--~`;
}
return val;
}).replace('\"~--demo--~', '').replace('~--demo--~\"', '').replace(/\\n/g, '');
});
do {
result = result.replace('\"~--demo--~', '').replace('~--demo--~\"', '').replace(/\\n/g, '').replace(/\\\"/g,"\"");//最后一个replace将release模式中莫名生成的\"转换成"
} while (result.indexOf('~--demo--~') >= 0);
return result;
}